@dxos/react-client 0.4.9 → 0.4.10-main.068c3d8
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/lib/browser/{chunk-Y64VSVTU.mjs → chunk-BQ4BAP42.mjs} +4 -3
- package/dist/lib/browser/chunk-BQ4BAP42.mjs.map +7 -0
- package/dist/lib/browser/echo/index.mjs +3 -4
- package/dist/lib/browser/echo/index.mjs.map +3 -3
- package/dist/lib/browser/halo/index.mjs +2 -3
- package/dist/lib/browser/halo/index.mjs.map +3 -3
- package/dist/lib/browser/invitations/index.mjs +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +2 -2
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/node/{chunk-PNDYOCJA.cjs → chunk-X5URYLUS.cjs} +7 -6
- package/dist/lib/node/chunk-X5URYLUS.cjs.map +7 -0
- package/dist/lib/node/echo/index.cjs +6 -7
- package/dist/lib/node/echo/index.cjs.map +3 -3
- package/dist/lib/node/halo/index.cjs +2 -4
- package/dist/lib/node/halo/index.cjs.map +2 -2
- package/dist/lib/node/invitations/index.cjs +7 -7
- package/dist/lib/node/invitations/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs +2 -2
- package/dist/lib/node/testing/index.cjs.map +3 -3
- package/dist/types/src/echo/useQuery.d.ts +2 -2
- package/dist/types/src/echo/useQuery.d.ts.map +1 -1
- package/dist/types/src/echo/useSpaceInvitations.d.ts.map +1 -1
- package/dist/types/src/halo/index.d.ts +1 -1
- package/dist/types/src/halo/index.d.ts.map +1 -1
- package/dist/types/src/invitations/useInvitationStatus.d.ts +1 -0
- package/dist/types/src/invitations/useInvitationStatus.d.ts.map +1 -1
- package/dist/types/src/testing/ClientRepeater.d.ts +3 -3
- package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
- package/package.json +17 -17
- package/src/echo/useQuery.ts +13 -4
- package/src/echo/useSpaceInvitations.ts +1 -2
- package/src/halo/index.ts +1 -10
- package/src/invitations/useInvitationStatus.ts +3 -0
- package/src/testing/ClientRepeater.tsx +6 -8
- package/dist/lib/browser/chunk-Y64VSVTU.mjs.map +0 -7
- package/dist/lib/node/chunk-PNDYOCJA.cjs.map +0 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-client",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.10-main.068c3d8",
|
|
4
4
|
"description": "React client API",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -83,17 +83,17 @@
|
|
|
83
83
|
}
|
|
84
84
|
},
|
|
85
85
|
"dependencies": {
|
|
86
|
-
"@dxos/async": "0.4.
|
|
87
|
-
"@dxos/client": "0.4.
|
|
88
|
-
"@dxos/
|
|
89
|
-
"@dxos/
|
|
90
|
-
"@dxos/echo-signals": "0.4.
|
|
91
|
-
"@dxos/invariant": "0.4.
|
|
92
|
-
"@dxos/debug": "0.4.
|
|
93
|
-
"@dxos/log": "0.4.
|
|
94
|
-
"@dxos/node-std": "0.4.
|
|
95
|
-
"@dxos/util": "0.4.
|
|
96
|
-
"@dxos/react-async": "0.4.
|
|
86
|
+
"@dxos/async": "0.4.10-main.068c3d8",
|
|
87
|
+
"@dxos/client": "0.4.10-main.068c3d8",
|
|
88
|
+
"@dxos/config": "0.4.10-main.068c3d8",
|
|
89
|
+
"@dxos/codec-protobuf": "0.4.10-main.068c3d8",
|
|
90
|
+
"@dxos/echo-signals": "0.4.10-main.068c3d8",
|
|
91
|
+
"@dxos/invariant": "0.4.10-main.068c3d8",
|
|
92
|
+
"@dxos/debug": "0.4.10-main.068c3d8",
|
|
93
|
+
"@dxos/log": "0.4.10-main.068c3d8",
|
|
94
|
+
"@dxos/node-std": "0.4.10-main.068c3d8",
|
|
95
|
+
"@dxos/util": "0.4.10-main.068c3d8",
|
|
96
|
+
"@dxos/react-async": "0.4.10-main.068c3d8"
|
|
97
97
|
},
|
|
98
98
|
"devDependencies": {
|
|
99
99
|
"@testing-library/dom": "^8.17.1",
|
|
@@ -104,10 +104,10 @@
|
|
|
104
104
|
"react": "^18.2.0",
|
|
105
105
|
"react-dom": "^18.2.0",
|
|
106
106
|
"yjs": "^13.6.10",
|
|
107
|
-
"@dxos/random": "0.4.
|
|
108
|
-
"@dxos/react-ui": "0.4.
|
|
109
|
-
"@dxos/react-ui-theme": "0.4.
|
|
110
|
-
"@dxos/storybook-utils": "0.4.
|
|
107
|
+
"@dxos/random": "0.4.10-main.068c3d8",
|
|
108
|
+
"@dxos/react-ui": "0.4.10-main.068c3d8",
|
|
109
|
+
"@dxos/react-ui-theme": "0.4.10-main.068c3d8",
|
|
110
|
+
"@dxos/storybook-utils": "0.4.10-main.068c3d8"
|
|
111
111
|
},
|
|
112
112
|
"peerDependencies": {
|
|
113
113
|
"react": "*",
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
},
|
|
116
116
|
"optionalDependencies": {
|
|
117
117
|
"yjs": "^13.6.10",
|
|
118
|
-
"@dxos/random": "0.4.
|
|
118
|
+
"@dxos/random": "0.4.10-main.068c3d8"
|
|
119
119
|
},
|
|
120
120
|
"publishConfig": {
|
|
121
121
|
"access": "public"
|
package/src/echo/useQuery.ts
CHANGED
|
@@ -4,17 +4,22 @@
|
|
|
4
4
|
|
|
5
5
|
import { useMemo, useSyncExternalStore } from 'react';
|
|
6
6
|
|
|
7
|
-
import type { QueryOptions,
|
|
7
|
+
import type { QueryOptions, Query, FilterSource, Space, EchoReactiveObject } from '@dxos/client/echo';
|
|
8
8
|
|
|
9
9
|
type UseQuery = {
|
|
10
|
-
<T extends
|
|
10
|
+
<T extends EchoReactiveObject<any>>(
|
|
11
|
+
space?: Space,
|
|
12
|
+
filter?: FilterSource<T>,
|
|
13
|
+
options?: QueryOptions,
|
|
14
|
+
deps?: any[],
|
|
15
|
+
): T[];
|
|
11
16
|
};
|
|
12
17
|
|
|
13
18
|
/**
|
|
14
19
|
* Create subscription.
|
|
15
20
|
*/
|
|
16
21
|
// TODO(burdon): Support typed operator filters (e.g., Note.filter(note => ...)).
|
|
17
|
-
export const useQuery: UseQuery = <T extends
|
|
22
|
+
export const useQuery: UseQuery = <T extends EchoReactiveObject<any>>(
|
|
18
23
|
space?: Space,
|
|
19
24
|
filter?: FilterSource<T>,
|
|
20
25
|
options?: QueryOptions,
|
|
@@ -34,4 +39,8 @@ export const useQuery: UseQuery = <T extends TypedObject>(
|
|
|
34
39
|
);
|
|
35
40
|
};
|
|
36
41
|
|
|
37
|
-
|
|
42
|
+
// TODO(dmaretskyi): Serialize the filter here instead.
|
|
43
|
+
const filterToDepsArray = (filter?: FilterSource<any>) =>
|
|
44
|
+
Object.entries(filter ?? {})
|
|
45
|
+
.flat(10)
|
|
46
|
+
.map((x) => (typeof x === 'function' || typeof x === 'object' ? null : x));
|
|
@@ -5,7 +5,6 @@
|
|
|
5
5
|
import { useMemo, useSyncExternalStore } from 'react';
|
|
6
6
|
|
|
7
7
|
import { type PublicKey } from '@dxos/client';
|
|
8
|
-
import { SpaceProxy } from '@dxos/client/echo';
|
|
9
8
|
|
|
10
9
|
import { useSpace } from './useSpaces';
|
|
11
10
|
import { useInvitationStatus } from '../invitations';
|
|
@@ -15,7 +14,7 @@ export const useSpaceInvitations = (spaceKey?: PublicKey) => {
|
|
|
15
14
|
const invitations =
|
|
16
15
|
useSyncExternalStore(
|
|
17
16
|
(listener) => {
|
|
18
|
-
if (!
|
|
17
|
+
if (!space) {
|
|
19
18
|
return () => {};
|
|
20
19
|
}
|
|
21
20
|
|
package/src/halo/index.ts
CHANGED
|
@@ -3,16 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
// NOTE: Export * fails here.
|
|
6
|
-
export {
|
|
7
|
-
type Contact,
|
|
8
|
-
Device,
|
|
9
|
-
DeviceKind,
|
|
10
|
-
DeviceType,
|
|
11
|
-
type Identity,
|
|
12
|
-
// generateSeedPhrase,
|
|
13
|
-
type Halo,
|
|
14
|
-
HaloProxy,
|
|
15
|
-
} from '@dxos/client/halo';
|
|
6
|
+
export { type Contact, type Identity, type Halo, Device, DeviceKind, DeviceType } from '@dxos/client/halo';
|
|
16
7
|
|
|
17
8
|
export * from './useContacts';
|
|
18
9
|
export * from './useDevices';
|
|
@@ -29,6 +29,7 @@ interface InvitationReducerState {
|
|
|
29
29
|
id?: string;
|
|
30
30
|
invitationCode?: string;
|
|
31
31
|
authCode?: string;
|
|
32
|
+
multiUse?: boolean;
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
export type InvitationAction =
|
|
@@ -65,6 +66,7 @@ export type InvitationStatus = {
|
|
|
65
66
|
type?: Invitation.Type;
|
|
66
67
|
status: Invitation.State;
|
|
67
68
|
haltedAt?: Invitation.State;
|
|
69
|
+
multiUse?: boolean;
|
|
68
70
|
result: InvitationResult;
|
|
69
71
|
error?: number;
|
|
70
72
|
cancel(): void;
|
|
@@ -179,6 +181,7 @@ export const useInvitationStatus = (initialObservable?: CancellableInvitationObs
|
|
|
179
181
|
connect,
|
|
180
182
|
authenticate,
|
|
181
183
|
id: invitation?.invitationId,
|
|
184
|
+
multiUse: invitation?.multiUse,
|
|
182
185
|
invitationCode: invitation ? InvitationEncoder.encode(invitation) : undefined,
|
|
183
186
|
authCode: invitation?.authCode,
|
|
184
187
|
authMethod: invitation?.authMethod,
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import React, { useState, type FC, useEffect } from 'react';
|
|
6
6
|
|
|
7
7
|
import { Client, type PublicKey } from '@dxos/client';
|
|
8
|
-
import { type
|
|
8
|
+
import { type Space } from '@dxos/client/echo';
|
|
9
9
|
import { TestBuilder, performInvitation } from '@dxos/client/testing';
|
|
10
10
|
import { registerSignalFactory } from '@dxos/echo-signals/react';
|
|
11
11
|
import { faker } from '@dxos/random';
|
|
@@ -19,12 +19,12 @@ export type RepeatedComponentProps = { id: number; count: number };
|
|
|
19
19
|
|
|
20
20
|
export type ClientRepeaterProps<P extends RepeatedComponentProps> = {
|
|
21
21
|
component: FC<any>;
|
|
22
|
+
className?: string;
|
|
22
23
|
controls?: FC<{ clients: Client[] }>;
|
|
23
24
|
clients?: Client[];
|
|
24
25
|
count?: number;
|
|
25
26
|
registerSignalFactory?: boolean;
|
|
26
|
-
|
|
27
|
-
types?: TypeCollection;
|
|
27
|
+
schema?: Parameters<Client['addSchema']>;
|
|
28
28
|
createIdentity?: boolean;
|
|
29
29
|
createSpace?: boolean;
|
|
30
30
|
onCreateSpace?: (space: Space) => MaybePromise<void>;
|
|
@@ -46,7 +46,7 @@ export const ClientRepeater = <P extends RepeatedComponentProps>(props: ClientRe
|
|
|
46
46
|
controls: Controls,
|
|
47
47
|
count = 1,
|
|
48
48
|
className = 'flex w-full place-content-evenly',
|
|
49
|
-
|
|
49
|
+
schema,
|
|
50
50
|
createIdentity,
|
|
51
51
|
createSpace,
|
|
52
52
|
onCreateSpace,
|
|
@@ -62,7 +62,7 @@ export const ClientRepeater = <P extends RepeatedComponentProps>(props: ClientRe
|
|
|
62
62
|
const timeout = setTimeout(async () => {
|
|
63
63
|
const clients = [...Array(count)].map((_) => new Client({ services: testBuilder.createLocal() }));
|
|
64
64
|
await Promise.all(clients.map((client) => client.initialize()));
|
|
65
|
-
|
|
65
|
+
schema && clients.map((client) => client.addSchema(...schema));
|
|
66
66
|
|
|
67
67
|
if (createIdentity || createSpace) {
|
|
68
68
|
await Promise.all(clients.map((client) => client.halo.createIdentity()));
|
|
@@ -72,9 +72,7 @@ export const ClientRepeater = <P extends RepeatedComponentProps>(props: ClientRe
|
|
|
72
72
|
const space = await clients[0].spaces.create({ name: faker.commerce.productName() });
|
|
73
73
|
setSpaceKey(space.key);
|
|
74
74
|
await onCreateSpace?.(space);
|
|
75
|
-
await Promise.all(
|
|
76
|
-
clients.slice(1).map((client) => performInvitation({ host: space as SpaceProxy, guest: client.spaces })),
|
|
77
|
-
);
|
|
75
|
+
await Promise.all(clients.slice(1).map((client) => performInvitation({ host: space, guest: client.spaces })));
|
|
78
76
|
}
|
|
79
77
|
|
|
80
78
|
setClients(clients);
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/invitations/index.ts", "../../../src/invitations/useInvitationStatus.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\n// NOTE: Export * fails here.\nexport {\n AuthenticatingInvitationObservable,\n CancellableInvitationObservable,\n InvitationEncoder,\n Invitation,\n type Invitations,\n InvitationsProxy,\n} from '@dxos/client/invitations';\n\nexport * from './useInvitationStatus';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useReducer, type Reducer, useMemo, useCallback, useEffect } from 'react';\n\nimport { type PublicKey } from '@dxos/client';\nimport {\n type AuthenticatingInvitationObservable,\n type CancellableInvitationObservable,\n Invitation,\n InvitationEncoder,\n} from '@dxos/client/invitations';\nimport { log } from '@dxos/log';\n\nexport type InvitationResult = {\n spaceKey: PublicKey | null;\n identityKey: PublicKey | null;\n swarmKey: PublicKey | null;\n target: string | null;\n};\n\ninterface InvitationReducerState {\n status: Invitation.State; // TODO(burdon): Rename state.\n haltedAt?: Invitation.State;\n result: InvitationResult;\n error?: number;\n observable?: CancellableInvitationObservable | AuthenticatingInvitationObservable;\n id?: string;\n invitationCode?: string;\n authCode?: string;\n}\n\nexport type InvitationAction =\n | {\n status:\n | Invitation.State.INIT\n | Invitation.State.CONNECTED\n | Invitation.State.READY_FOR_AUTHENTICATION\n | Invitation.State.AUTHENTICATING;\n }\n | {\n status: Invitation.State.CONNECTING;\n observable: CancellableInvitationObservable;\n }\n | {\n status: Invitation.State.SUCCESS;\n result: InvitationResult;\n }\n | {\n status: Invitation.State.CANCELLED | Invitation.State.TIMEOUT;\n haltedAt: Invitation.State;\n }\n | {\n status: Invitation.State.ERROR;\n error?: Error;\n haltedAt: Invitation.State;\n };\n\nexport type InvitationStatus = {\n id?: string;\n invitationCode?: string;\n authCode?: string;\n authMethod?: Invitation.AuthMethod;\n type?: Invitation.Type;\n status: Invitation.State;\n haltedAt?: Invitation.State;\n result: InvitationResult;\n error?: number;\n cancel(): void;\n // TODO(wittjosiah): Remove?\n connect(observable: CancellableInvitationObservable): void;\n authenticate(authCode: string): Promise<void>;\n};\n\nexport const useInvitationStatus = (initialObservable?: CancellableInvitationObservable): InvitationStatus => {\n const [state, dispatch] = useReducer<Reducer<InvitationReducerState, InvitationAction>, null>(\n (prev, action) => {\n log('useInvitationStatus', { action });\n return {\n ...prev,\n // TODO(burdon): State.\n status: action.status,\n // `invitationObservable`, `secret`, and `result` is persisted between the status-actions that set them.\n result: action.status === Invitation.State.SUCCESS ? action.result : prev.result,\n // `error` gets set each time we enter the error state\n ...(action.status === Invitation.State.ERROR && { error: action.error }),\n // `haltedAt` gets set on only the first error/cancelled/timeout action and reset on any others.\n ...((action.status === Invitation.State.ERROR ||\n action.status === Invitation.State.CANCELLED ||\n action.status === Invitation.State.TIMEOUT) && {\n haltedAt: typeof prev.haltedAt === 'undefined' ? action.haltedAt : prev.haltedAt,\n }),\n observable:\n action.status === Invitation.State.CONNECTING ? action.observable ?? prev.observable : prev.observable,\n } as InvitationReducerState;\n },\n null,\n (_arg: null) => {\n return {\n status: Invitation.State.INIT,\n result: { spaceKey: null, identityKey: null, swarmKey: null, target: null },\n observable: initialObservable,\n };\n },\n );\n\n // Handle unmount.\n\n useEffect(() => {\n const update = (invitation: Invitation) => {\n switch (invitation.state) {\n case Invitation.State.CONNECTED:\n case Invitation.State.READY_FOR_AUTHENTICATION:\n case Invitation.State.AUTHENTICATING: {\n dispatch({\n status: invitation.state,\n });\n break;\n }\n\n case Invitation.State.SUCCESS: {\n dispatch({\n status: invitation.state,\n result: {\n spaceKey: invitation.spaceKey || null,\n identityKey: invitation.identityKey || null,\n swarmKey: invitation.swarmKey || null,\n target: invitation.target || null,\n },\n });\n break;\n }\n\n case Invitation.State.CANCELLED:\n case Invitation.State.TIMEOUT: {\n dispatch({ status: invitation.state, haltedAt: state.status });\n break;\n }\n }\n };\n\n const subscription = state.observable?.subscribe(update, (err: Error) => {\n dispatch({ status: Invitation.State.ERROR, error: err, haltedAt: state.status });\n });\n\n const currentState = state.observable?.get();\n if (currentState) {\n update(currentState);\n }\n\n return () => subscription?.unsubscribe();\n }, [state.observable, state.status]);\n\n // Return memoized callbacks & values.\n\n const connect = useCallback((observable: CancellableInvitationObservable) => {\n dispatch({ status: Invitation.State.CONNECTING, observable });\n }, []);\n\n const authenticate = useCallback(\n (authCode: string) => {\n log('authenticating...', { authCode });\n return (state.observable as AuthenticatingInvitationObservable).authenticate(authCode);\n },\n [state.observable],\n );\n\n const cancel = useCallback(async () => state.observable?.cancel(), [state.observable]);\n\n return useMemo(() => {\n const invitation = state.observable?.get();\n const result = {\n status: state.status,\n haltedAt: state.haltedAt,\n result: state.result,\n error: state.error,\n cancel,\n connect,\n authenticate,\n id: invitation?.invitationId,\n invitationCode: invitation ? InvitationEncoder.encode(invitation) : undefined,\n authCode: invitation?.authCode,\n authMethod: invitation?.authMethod,\n type: invitation?.type,\n };\n\n return result;\n }, [state, cancel, connect, authenticate]);\n};\n"],
|
|
5
|
-
"mappings": ";AAKA,SACEA,oCACAC,iCACAC,qBAAAA,oBACAC,cAAAA,aAEAC,wBACK;;;ACRP,SAASC,YAA0BC,SAASC,aAAaC,iBAAiB;AAG1E,SAGEC,YACAC,yBACK;AACP,SAASC,WAAW;;AA8Db,IAAMC,sBAAsB,CAACC,sBAAAA;AAClC,QAAM,CAACC,OAAOC,QAAAA,IAAYV,WACxB,CAACW,MAAMC,WAAAA;AACLN,QAAI,uBAAuB;MAAEM;IAAO,GAAA;;;;;;AACpC,WAAO;MACL,GAAGD;;MAEHE,QAAQD,OAAOC;;MAEfC,QAAQF,OAAOC,WAAWT,WAAWW,MAAMC,UAAUJ,OAAOE,SAASH,KAAKG;;MA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G,QAAQT,WAAWW,MAAME;QAAOC,OAAOmB;QAAKhB,UAAUZ,MAAMI;MAAO,CAAA;IAChF,CAAA;AAEA,UAAMyB,eAAe7B,MAAMa,YAAYiB,IAAAA;AACvC,QAAID,cAAc;AAChBR,aAAOQ,YAAAA;IACT;AAEA,WAAO,MAAMH,cAAcK,YAAAA;EAC7B,GAAG;IAAC/B,MAAMa;IAAYb,MAAMI;GAAO;AAInC,QAAM4B,UAAUvC,YAAY,CAACoB,eAAAA;AAC3BZ,aAAS;MAAEG,QAAQT,WAAWW,MAAMQ;MAAYD;IAAW,CAAA;EAC7D,GAAG,CAAA,CAAE;AAEL,QAAMoB,eAAexC,YACnB,CAACyC,aAAAA;AACCrC,QAAI,qBAAqB;MAAEqC;IAAS,GAAA;;;;;;AACpC,WAAQlC,MAAMa,WAAkDoB,aAAaC,QAAAA;EAC/E,GACA;IAAClC,MAAMa;GAAW;AAGpB,QAAMsB,SAAS1C,YAAY,YAAYO,MAAMa,YAAYsB,OAAAA,GAAU;IAACnC,MAAMa;GAAW;AAErF,SAAOrB,QAAQ,MAAA;AACb,UAAM8B,aAAatB,MAAMa,YAAYiB,IAAAA;AACrC,UAAMzB,SAAS;MACbD,QAAQJ,MAAMI;MACdQ,UAAUZ,MAAMY;MAChBP,QAAQL,MAAMK;MACdI,OAAOT,MAAMS;MACb0B;MACAH;MACAC;MACAG,IAAId,YAAYe;MAChBC,gBAAgBhB,aAAa1B,kBAAkB2C,OAAOjB,UAAAA,IAAckB;MACpEN,UAAUZ,YAAYY;MACtBO,YAAYnB,YAAYmB;MACxBC,MAAMpB,YAAYoB;IACpB;AAEA,WAAOrC;EACT,GAAG;IAACL;IAAOmC;IAAQH;IAASC;GAAa;AAC3C;",
|
|
6
|
-
"names": ["AuthenticatingInvitationObservable", "CancellableInvitationObservable", "InvitationEncoder", "Invitation", "InvitationsProxy", "useReducer", "useMemo", "useCallback", "useEffect", "Invitation", "InvitationEncoder", "log", "useInvitationStatus", "initialObservable", "state", "dispatch", "prev", "action", "status", "result", "State", "SUCCESS", "ERROR", "error", "CANCELLED", "TIMEOUT", "haltedAt", "observable", "CONNECTING", "_arg", "INIT", "spaceKey", "identityKey", "swarmKey", "target", "update", "invitation", "CONNECTED", "READY_FOR_AUTHENTICATION", "AUTHENTICATING", "subscription", "subscribe", "err", "currentState", "get", "unsubscribe", "connect", "authenticate", "authCode", "cancel", "id", "invitationId", "invitationCode", "encode", "undefined", "authMethod", "type"]
|
|
7
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": 3,
|
|
3
|
-
"sources": ["../../../src/invitations/index.ts", "../../../src/invitations/useInvitationStatus.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\n// NOTE: Export * fails here.\nexport {\n AuthenticatingInvitationObservable,\n CancellableInvitationObservable,\n InvitationEncoder,\n Invitation,\n type Invitations,\n InvitationsProxy,\n} from '@dxos/client/invitations';\n\nexport * from './useInvitationStatus';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { useReducer, type Reducer, useMemo, useCallback, useEffect } from 'react';\n\nimport { type PublicKey } from '@dxos/client';\nimport {\n type AuthenticatingInvitationObservable,\n type CancellableInvitationObservable,\n Invitation,\n InvitationEncoder,\n} from '@dxos/client/invitations';\nimport { log } from '@dxos/log';\n\nexport type InvitationResult = {\n spaceKey: PublicKey | null;\n identityKey: PublicKey | null;\n swarmKey: PublicKey | null;\n target: string | null;\n};\n\ninterface InvitationReducerState {\n status: Invitation.State; // TODO(burdon): Rename state.\n haltedAt?: Invitation.State;\n result: InvitationResult;\n error?: number;\n observable?: CancellableInvitationObservable | AuthenticatingInvitationObservable;\n id?: string;\n invitationCode?: string;\n authCode?: string;\n}\n\nexport type InvitationAction =\n | {\n status:\n | Invitation.State.INIT\n | Invitation.State.CONNECTED\n | Invitation.State.READY_FOR_AUTHENTICATION\n | Invitation.State.AUTHENTICATING;\n }\n | {\n status: Invitation.State.CONNECTING;\n observable: CancellableInvitationObservable;\n }\n | {\n status: Invitation.State.SUCCESS;\n result: InvitationResult;\n }\n | {\n status: Invitation.State.CANCELLED | Invitation.State.TIMEOUT;\n haltedAt: Invitation.State;\n }\n | {\n status: Invitation.State.ERROR;\n error?: Error;\n haltedAt: Invitation.State;\n };\n\nexport type InvitationStatus = {\n id?: string;\n invitationCode?: string;\n authCode?: string;\n authMethod?: Invitation.AuthMethod;\n type?: Invitation.Type;\n status: Invitation.State;\n haltedAt?: Invitation.State;\n result: InvitationResult;\n error?: number;\n cancel(): void;\n // TODO(wittjosiah): Remove?\n connect(observable: CancellableInvitationObservable): void;\n authenticate(authCode: string): Promise<void>;\n};\n\nexport const useInvitationStatus = (initialObservable?: CancellableInvitationObservable): InvitationStatus => {\n const [state, dispatch] = useReducer<Reducer<InvitationReducerState, InvitationAction>, null>(\n (prev, action) => {\n log('useInvitationStatus', { action });\n return {\n ...prev,\n // TODO(burdon): State.\n status: action.status,\n // `invitationObservable`, `secret`, and `result` is persisted between the status-actions that set them.\n result: action.status === Invitation.State.SUCCESS ? action.result : prev.result,\n // `error` gets set each time we enter the error state\n ...(action.status === Invitation.State.ERROR && { error: action.error }),\n // `haltedAt` gets set on only the first error/cancelled/timeout action and reset on any others.\n ...((action.status === Invitation.State.ERROR ||\n action.status === Invitation.State.CANCELLED ||\n action.status === Invitation.State.TIMEOUT) && {\n haltedAt: typeof prev.haltedAt === 'undefined' ? action.haltedAt : prev.haltedAt,\n }),\n observable:\n action.status === Invitation.State.CONNECTING ? action.observable ?? prev.observable : prev.observable,\n } as InvitationReducerState;\n },\n null,\n (_arg: null) => {\n return {\n status: Invitation.State.INIT,\n result: { spaceKey: null, identityKey: null, swarmKey: null, target: null },\n observable: initialObservable,\n };\n },\n );\n\n // Handle unmount.\n\n useEffect(() => {\n const update = (invitation: Invitation) => {\n switch (invitation.state) {\n case Invitation.State.CONNECTED:\n case Invitation.State.READY_FOR_AUTHENTICATION:\n case Invitation.State.AUTHENTICATING: {\n dispatch({\n status: invitation.state,\n });\n break;\n }\n\n case Invitation.State.SUCCESS: {\n dispatch({\n status: invitation.state,\n result: {\n spaceKey: invitation.spaceKey || null,\n identityKey: invitation.identityKey || null,\n swarmKey: invitation.swarmKey || null,\n target: invitation.target || null,\n },\n });\n break;\n }\n\n case Invitation.State.CANCELLED:\n case Invitation.State.TIMEOUT: {\n dispatch({ status: invitation.state, haltedAt: state.status });\n break;\n }\n }\n };\n\n const subscription = state.observable?.subscribe(update, (err: Error) => {\n dispatch({ status: Invitation.State.ERROR, error: err, haltedAt: state.status });\n });\n\n const currentState = state.observable?.get();\n if (currentState) {\n update(currentState);\n }\n\n return () => subscription?.unsubscribe();\n }, [state.observable, state.status]);\n\n // Return memoized callbacks & values.\n\n const connect = useCallback((observable: CancellableInvitationObservable) => {\n dispatch({ status: Invitation.State.CONNECTING, observable });\n }, []);\n\n const authenticate = useCallback(\n (authCode: string) => {\n log('authenticating...', { authCode });\n return (state.observable as AuthenticatingInvitationObservable).authenticate(authCode);\n },\n [state.observable],\n );\n\n const cancel = useCallback(async () => state.observable?.cancel(), [state.observable]);\n\n return useMemo(() => {\n const invitation = state.observable?.get();\n const result = {\n status: state.status,\n haltedAt: state.haltedAt,\n result: state.result,\n error: state.error,\n cancel,\n connect,\n authenticate,\n id: invitation?.invitationId,\n invitationCode: invitation ? InvitationEncoder.encode(invitation) : undefined,\n authCode: invitation?.authCode,\n authMethod: invitation?.authMethod,\n type: invitation?.type,\n };\n\n return result;\n }, [state, cancel, connect, authenticate]);\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAKA,yBAOO;ACRP,mBAA0E;AAG1E,IAAAA,sBAKO;AACP,iBAAoB;;AA8Db,IAAMC,sBAAsB,CAACC,sBAAAA;AAClC,QAAM,CAACC,OAAOC,QAAAA,QAAYC,yBACxB,CAACC,MAAMC,WAAAA;AACLC,wBAAI,uBAAuB;MAAED;IAAO,GAAA;;;;;;AACpC,WA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|
-
"names": ["import_invitations", "useInvitationStatus", "initialObservable", "state", "dispatch", "useReducer", "prev", "action", "log", "status", "result", "Invitation", "State", "SUCCESS", "ERROR", "error", "CANCELLED", "TIMEOUT", "haltedAt", "observable", "CONNECTING", "_arg", "INIT", "spaceKey", "identityKey", "swarmKey", "target", "useEffect", "update", "invitation", "CONNECTED", "READY_FOR_AUTHENTICATION", "AUTHENTICATING", "subscription", "subscribe", "err", "currentState", "get", "unsubscribe", "connect", "useCallback", "authenticate", "authCode", "cancel", "useMemo", "id", "invitationId", "invitationCode", "InvitationEncoder", "encode", "undefined", "authMethod", "type"]
|
|
7
|
-
}
|