@dxos/react-client 0.7.1 → 0.7.2-main.f1adc9f
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/echo/index.mjs.map +1 -1
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs.map +2 -2
- package/dist/lib/node/echo/index.cjs.map +1 -1
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/testing/index.cjs.map +2 -2
- package/dist/lib/node-esm/echo/index.mjs.map +1 -1
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs.map +2 -2
- package/dist/types/src/echo/useQuery.d.ts +2 -2
- package/dist/types/src/testing/ClientRepeater.d.ts +2 -2
- package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
- package/package.json +23 -23
- package/src/echo/useQuery.ts +2 -2
- package/src/testing/ClientRepeater.tsx +2 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/testing/index.ts", "../../../../src/testing/ClientRepeater.tsx", "../../../../src/testing/withClientProvider.tsx"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nexport * from '@dxos/client/testing';\n\nexport * from './ClientRepeater';\nexport * from './withClientProvider';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport { type Schema as S } from '@effect/schema';\nimport React, { useState, type FC, useEffect, useRef } from 'react';\n\nimport { Client, type PublicKey } from '@dxos/client';\nimport { TestBuilder, performInvitation } from '@dxos/client/testing';\nimport { registerSignalsRuntime } from '@dxos/echo-signals/react';\nimport { faker } from '@dxos/random';\n\nimport { type WithClientProviderProps } from './withClientProvider';\nimport { ClientProvider } from '../client';\n\nexport type ClientRepeatedComponentProps = { id: number; count: number; spaceKey?: PublicKey };\n\nexport type ClientRepeaterControlsProps = { clients: Client[] };\n\n// TODO(burdon): Reconcile with ClientProviderProps.\nexport type ClientRepeaterProps<P extends ClientRepeatedComponentProps> = {\n className?: string;\n component: FC<ClientRepeatedComponentProps>;\n controls?: FC<ClientRepeaterControlsProps>;\n count?: number;\n clients?: Client[];\n types?: S.Schema<any>[];\n args?: Omit<P, 'id' | 'count'>;\n} & Pick<WithClientProviderProps, 'createIdentity' | 'createSpace' | 'onSpaceCreated'>;\n\n/**\n * Utility component for Storybook stories which sets up clients for n peers.\n * The `Component` property is rendered n times, once for each peer.\n * @deprecated use `withClientProvider`.\n */\n// TODO(burdon): To discuss: evolve ClientRepeater with optional decorator that uses it.\n// NOTE: This is specifically not a storybook decorator because it broke stories as a decorator.\n// This seems primarily due to the fact that it required top-level await for the clients to initialize.\n// Storybook seemed to handle it alright, but Chromatic had a lot of trouble with it.\n// There was also a question of whether or not calling the story function multiple times was a good idea.\nexport const ClientRepeater = <P extends ClientRepeatedComponentProps>(props: ClientRepeaterProps<P>) => {\n const {\n component: Component,\n controls: Controls,\n count = 1,\n types,\n createIdentity,\n createSpace,\n onSpaceCreated,\n } = props;\n useEffect(() => {\n registerSignalsRuntime();\n }, []);\n\n const [clients, setClients] = useState(props.clients ?? []);\n const [spaceKey, setSpaceKey] = useState<PublicKey>();\n\n const testBuilder = useRef(new TestBuilder());\n useEffect(() => {\n const timeout = setTimeout(async () => {\n const clients = [...Array(count)].map(\n (_) => new Client({ services: testBuilder.current.createLocalClientServices(), types }),\n );\n\n await Promise.all(clients.map((client) => client.initialize()));\n if (createIdentity || createSpace) {\n await Promise.all(clients.map((client) => client.halo.createIdentity()));\n }\n\n if (createSpace) {\n const client = clients[0];\n const space = await client.spaces.create({ name: faker.commerce.productName() });\n setSpaceKey(space.key);\n await onSpaceCreated?.({ client, space });\n await Promise.all(\n clients.slice(1).flatMap((client) => performInvitation({ host: space, guest: client.spaces })),\n );\n }\n\n setClients(clients);\n });\n\n return () => clearTimeout(timeout);\n }, []);\n\n if (clients.length === 0) {\n return null;\n }\n\n return (\n <>\n {Controls && <Controls clients={clients} />}\n {clients.map((client, index) => (\n <ClientProvider key={index} client={client}>\n <Component id={index} count={clients.length} spaceKey={spaceKey} {...{ ...props.args }} />\n </ClientProvider>\n ))}\n </>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Decorator } from '@storybook/react';\nimport React, { createContext, type PropsWithChildren, useContext, useEffect, useRef, useState } from 'react';\nimport { type FallbackProps, ErrorBoundary as NativeErrorBoundary } from 'react-error-boundary';\n\nimport { Trigger } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport { performInvitation, TestBuilder } from '@dxos/client/testing';\nimport { raise } from '@dxos/debug';\nimport { log } from '@dxos/log';\nimport { type MaybePromise } from '@dxos/util';\n\nimport { ClientProvider, type ClientProviderProps } from '../client';\n\ntype InitializeProps = {\n createIdentity?: boolean;\n createSpace?: boolean;\n onInitialized?: (client: Client) => MaybePromise<Record<string, any> | void>;\n onSpaceCreated?: (props: { client: Client; space: Space }) => MaybePromise<Record<string, any> | void>;\n};\n\n/**\n * Initialize client, identity and first space.\n */\nconst initializeClient = async (\n client: Client,\n { createIdentity, createSpace, onSpaceCreated, onInitialized }: InitializeProps,\n): Promise<StoryClientProps> => {\n const clientData = await onInitialized?.(client);\n\n if (createIdentity || createSpace) {\n if (!client.halo.identity.get()) {\n await client.halo.createIdentity();\n }\n }\n\n let space: Space | undefined;\n let spaceData: Record<string, any> | void = {};\n if (createSpace) {\n space = await client.spaces.create({ name: 'Test Space' });\n spaceData = await onSpaceCreated?.({ client, space });\n }\n\n return { space, ...clientData, ...spaceData };\n};\n\ntype StoryClientProps<T extends Record<string, any> = Record<string, unknown>> = T & { space?: Space };\n\n// TODO(wittjosiah): Add to multi-client as well.\nconst StoryClientContext = createContext<StoryClientProps | undefined>(undefined);\n\nexport const useStoryClientData = <T extends Record<string, any> = Record<string, unknown>>() => {\n const data = useContext(StoryClientContext) ?? raise(new Error('Missing withClientProvider decorator.'));\n return data as StoryClientProps<T>;\n};\n\nexport type WithClientProviderProps = InitializeProps & Omit<ClientProviderProps, 'onInitialized'>;\n\n/**\n * Decorator that provides the client context.\n */\nexport const withClientProvider = ({\n createIdentity,\n createSpace,\n onSpaceCreated,\n onInitialized,\n ...props\n}: WithClientProviderProps = {}): Decorator => {\n return (Story) => {\n const [data, setData] = useState<StoryClientProps>({});\n\n const handleInitialized = async (client: Client) => {\n setData(await initializeClient(client, { createIdentity, createSpace, onSpaceCreated, onInitialized }));\n };\n\n return (\n <ErrorBoundary>\n <ClientProvider onInitialized={handleInitialized} {...props}>\n <StoryClientContext.Provider value={data}>\n <Story />\n </StoryClientContext.Provider>\n </ClientProvider>\n </ErrorBoundary>\n );\n };\n};\n\n// TODO(burdon): Implement context per client for context.\n// TODO(burdon): Callback once all invitations have completed.\n// TODO(burdon): Delay/jitter for creation of other clients.\nexport type WithMultiClientProviderProps = InitializeProps &\n Omit<ClientProviderProps, 'onInitialized'> & { numClients?: number };\n\nconst MultiClientContext = createContext<{ id: number }>({ id: 0 });\n\nexport const useMultiClient = () => useContext(MultiClientContext);\n\n/**\n * Decorator that creates a scaffold for multiple clients.\n * Orchestrates invitations between a randomly selected host and the remaining clients.\n * NOTE: Should come before withLayout.\n */\nexport const withMultiClientProvider = ({\n numClients = 2,\n createIdentity,\n createSpace,\n onSpaceCreated,\n onInitialized,\n ...props\n}: WithMultiClientProviderProps): Decorator => {\n return (Story) => {\n const builder = useRef(new TestBuilder());\n const hostRef = useRef<Client>();\n const spaceReady = useRef(new Trigger<Space | undefined>());\n\n // Handle invitations.\n // NOTE: The zeroth client isn't necessarily the first to be initialized.\n const handleInitialized = async (client: Client, index: number) => {\n log.info('initialized', { index });\n if (createSpace) {\n if (!hostRef.current) {\n hostRef.current = client;\n const { space } = await initializeClient(client, {\n createIdentity,\n createSpace,\n onSpaceCreated,\n onInitialized,\n });\n spaceReady.current.wake(space);\n log.info('inviting', { index });\n } else {\n await initializeClient(client, { createIdentity, onInitialized });\n const space = await spaceReady.current.wait();\n if (space) {\n log.info('joining', { index });\n await Promise.all(performInvitation({ host: space, guest: client.spaces }));\n }\n }\n }\n };\n\n return (\n <ErrorBoundary>\n {Array.from({ length: numClients }).map((_, index) => (\n <MultiClientContext.Provider key={index} value={{ id: index }}>\n <ClientProvider\n services={builder.current.createLocalClientServices()}\n onInitialized={(client) => handleInitialized(client, index)}\n {...props}\n >\n <Story />\n </ClientProvider>\n </MultiClientContext.Provider>\n ))}\n </ErrorBoundary>\n );\n };\n};\n\nconst ErrorBoundary = ({ children }: PropsWithChildren) => {\n const [error, setError] = useState<Error>();\n useEffect(() => {\n const handleError = (event: PromiseRejectionEvent) => {\n setError(event.reason);\n };\n\n window.addEventListener('unhandledrejection', handleError);\n return () => window.removeEventListener('unhandledrejection', handleError);\n }, []);\n\n if (error) {\n return <ErrorFallback error={error} resetErrorBoundary={() => setError(undefined)} />;\n }\n\n return <NativeErrorBoundary FallbackComponent={ErrorFallback}>{children}</NativeErrorBoundary>;\n};\n\nconst ErrorFallback = ({ error }: FallbackProps) => {\n const { name, message, stack } =\n error instanceof Error ? error : { name: 'Error', message: String(error), stack: undefined };\n return (\n <div role='alert' className='flex flex-col p-4 gap-4 overflow-auto'>\n <h1 className='text-xl text-red-500'>{name}</h1>\n <div className='text-lg'>{message}</div>\n {stack && <pre className='whitespace-pre-wrap text-sm text-subdued'>{stack}</pre>}\n </div>\n );\n};\n"],
|
|
5
|
-
"mappings": ";;;;;;AAIA,cAAc;;;
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2020 DXOS.org\n//\n\nexport * from '@dxos/client/testing';\n\nexport * from './ClientRepeater';\nexport * from './withClientProvider';\n", "//\n// Copyright 2022 DXOS.org\n//\n\nimport React, { useState, type FC, useEffect, useRef } from 'react';\n\nimport { Client, type PublicKey } from '@dxos/client';\nimport { TestBuilder, performInvitation } from '@dxos/client/testing';\nimport { type AbstractTypedObject } from '@dxos/echo-schema';\nimport { registerSignalsRuntime } from '@dxos/echo-signals/react';\nimport { faker } from '@dxos/random';\n\nimport { type WithClientProviderProps } from './withClientProvider';\nimport { ClientProvider } from '../client';\n\nexport type ClientRepeatedComponentProps = { id: number; count: number; spaceKey?: PublicKey };\n\nexport type ClientRepeaterControlsProps = { clients: Client[] };\n\n// TODO(burdon): Reconcile with ClientProviderProps.\nexport type ClientRepeaterProps<P extends ClientRepeatedComponentProps> = {\n className?: string;\n component: FC<ClientRepeatedComponentProps>;\n controls?: FC<ClientRepeaterControlsProps>;\n count?: number;\n clients?: Client[];\n types?: AbstractTypedObject[];\n args?: Omit<P, 'id' | 'count'>;\n} & Pick<WithClientProviderProps, 'createIdentity' | 'createSpace' | 'onSpaceCreated'>;\n\n/**\n * Utility component for Storybook stories which sets up clients for n peers.\n * The `Component` property is rendered n times, once for each peer.\n * @deprecated use `withClientProvider`.\n */\n// TODO(burdon): To discuss: evolve ClientRepeater with optional decorator that uses it.\n// NOTE: This is specifically not a storybook decorator because it broke stories as a decorator.\n// This seems primarily due to the fact that it required top-level await for the clients to initialize.\n// Storybook seemed to handle it alright, but Chromatic had a lot of trouble with it.\n// There was also a question of whether or not calling the story function multiple times was a good idea.\nexport const ClientRepeater = <P extends ClientRepeatedComponentProps>(props: ClientRepeaterProps<P>) => {\n const {\n component: Component,\n controls: Controls,\n count = 1,\n types,\n createIdentity,\n createSpace,\n onSpaceCreated,\n } = props;\n useEffect(() => {\n registerSignalsRuntime();\n }, []);\n\n const [clients, setClients] = useState(props.clients ?? []);\n const [spaceKey, setSpaceKey] = useState<PublicKey>();\n\n const testBuilder = useRef(new TestBuilder());\n useEffect(() => {\n const timeout = setTimeout(async () => {\n const clients = [...Array(count)].map(\n (_) => new Client({ services: testBuilder.current.createLocalClientServices(), types }),\n );\n\n await Promise.all(clients.map((client) => client.initialize()));\n if (createIdentity || createSpace) {\n await Promise.all(clients.map((client) => client.halo.createIdentity()));\n }\n\n if (createSpace) {\n const client = clients[0];\n const space = await client.spaces.create({ name: faker.commerce.productName() });\n setSpaceKey(space.key);\n await onSpaceCreated?.({ client, space });\n await Promise.all(\n clients.slice(1).flatMap((client) => performInvitation({ host: space, guest: client.spaces })),\n );\n }\n\n setClients(clients);\n });\n\n return () => clearTimeout(timeout);\n }, []);\n\n if (clients.length === 0) {\n return null;\n }\n\n return (\n <>\n {Controls && <Controls clients={clients} />}\n {clients.map((client, index) => (\n <ClientProvider key={index} client={client}>\n <Component id={index} count={clients.length} spaceKey={spaceKey} {...{ ...props.args }} />\n </ClientProvider>\n ))}\n </>\n );\n};\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { type Decorator } from '@storybook/react';\nimport React, { createContext, type PropsWithChildren, useContext, useEffect, useRef, useState } from 'react';\nimport { type FallbackProps, ErrorBoundary as NativeErrorBoundary } from 'react-error-boundary';\n\nimport { Trigger } from '@dxos/async';\nimport { type Client } from '@dxos/client';\nimport { type Space } from '@dxos/client/echo';\nimport { performInvitation, TestBuilder } from '@dxos/client/testing';\nimport { raise } from '@dxos/debug';\nimport { log } from '@dxos/log';\nimport { type MaybePromise } from '@dxos/util';\n\nimport { ClientProvider, type ClientProviderProps } from '../client';\n\ntype InitializeProps = {\n createIdentity?: boolean;\n createSpace?: boolean;\n onInitialized?: (client: Client) => MaybePromise<Record<string, any> | void>;\n onSpaceCreated?: (props: { client: Client; space: Space }) => MaybePromise<Record<string, any> | void>;\n};\n\n/**\n * Initialize client, identity and first space.\n */\nconst initializeClient = async (\n client: Client,\n { createIdentity, createSpace, onSpaceCreated, onInitialized }: InitializeProps,\n): Promise<StoryClientProps> => {\n const clientData = await onInitialized?.(client);\n\n if (createIdentity || createSpace) {\n if (!client.halo.identity.get()) {\n await client.halo.createIdentity();\n }\n }\n\n let space: Space | undefined;\n let spaceData: Record<string, any> | void = {};\n if (createSpace) {\n space = await client.spaces.create({ name: 'Test Space' });\n spaceData = await onSpaceCreated?.({ client, space });\n }\n\n return { space, ...clientData, ...spaceData };\n};\n\ntype StoryClientProps<T extends Record<string, any> = Record<string, unknown>> = T & { space?: Space };\n\n// TODO(wittjosiah): Add to multi-client as well.\nconst StoryClientContext = createContext<StoryClientProps | undefined>(undefined);\n\nexport const useStoryClientData = <T extends Record<string, any> = Record<string, unknown>>() => {\n const data = useContext(StoryClientContext) ?? raise(new Error('Missing withClientProvider decorator.'));\n return data as StoryClientProps<T>;\n};\n\nexport type WithClientProviderProps = InitializeProps & Omit<ClientProviderProps, 'onInitialized'>;\n\n/**\n * Decorator that provides the client context.\n */\nexport const withClientProvider = ({\n createIdentity,\n createSpace,\n onSpaceCreated,\n onInitialized,\n ...props\n}: WithClientProviderProps = {}): Decorator => {\n return (Story) => {\n const [data, setData] = useState<StoryClientProps>({});\n\n const handleInitialized = async (client: Client) => {\n setData(await initializeClient(client, { createIdentity, createSpace, onSpaceCreated, onInitialized }));\n };\n\n return (\n <ErrorBoundary>\n <ClientProvider onInitialized={handleInitialized} {...props}>\n <StoryClientContext.Provider value={data}>\n <Story />\n </StoryClientContext.Provider>\n </ClientProvider>\n </ErrorBoundary>\n );\n };\n};\n\n// TODO(burdon): Implement context per client for context.\n// TODO(burdon): Callback once all invitations have completed.\n// TODO(burdon): Delay/jitter for creation of other clients.\nexport type WithMultiClientProviderProps = InitializeProps &\n Omit<ClientProviderProps, 'onInitialized'> & { numClients?: number };\n\nconst MultiClientContext = createContext<{ id: number }>({ id: 0 });\n\nexport const useMultiClient = () => useContext(MultiClientContext);\n\n/**\n * Decorator that creates a scaffold for multiple clients.\n * Orchestrates invitations between a randomly selected host and the remaining clients.\n * NOTE: Should come before withLayout.\n */\nexport const withMultiClientProvider = ({\n numClients = 2,\n createIdentity,\n createSpace,\n onSpaceCreated,\n onInitialized,\n ...props\n}: WithMultiClientProviderProps): Decorator => {\n return (Story) => {\n const builder = useRef(new TestBuilder());\n const hostRef = useRef<Client>();\n const spaceReady = useRef(new Trigger<Space | undefined>());\n\n // Handle invitations.\n // NOTE: The zeroth client isn't necessarily the first to be initialized.\n const handleInitialized = async (client: Client, index: number) => {\n log.info('initialized', { index });\n if (createSpace) {\n if (!hostRef.current) {\n hostRef.current = client;\n const { space } = await initializeClient(client, {\n createIdentity,\n createSpace,\n onSpaceCreated,\n onInitialized,\n });\n spaceReady.current.wake(space);\n log.info('inviting', { index });\n } else {\n await initializeClient(client, { createIdentity, onInitialized });\n const space = await spaceReady.current.wait();\n if (space) {\n log.info('joining', { index });\n await Promise.all(performInvitation({ host: space, guest: client.spaces }));\n }\n }\n }\n };\n\n return (\n <ErrorBoundary>\n {Array.from({ length: numClients }).map((_, index) => (\n <MultiClientContext.Provider key={index} value={{ id: index }}>\n <ClientProvider\n services={builder.current.createLocalClientServices()}\n onInitialized={(client) => handleInitialized(client, index)}\n {...props}\n >\n <Story />\n </ClientProvider>\n </MultiClientContext.Provider>\n ))}\n </ErrorBoundary>\n );\n };\n};\n\nconst ErrorBoundary = ({ children }: PropsWithChildren) => {\n const [error, setError] = useState<Error>();\n useEffect(() => {\n const handleError = (event: PromiseRejectionEvent) => {\n setError(event.reason);\n };\n\n window.addEventListener('unhandledrejection', handleError);\n return () => window.removeEventListener('unhandledrejection', handleError);\n }, []);\n\n if (error) {\n return <ErrorFallback error={error} resetErrorBoundary={() => setError(undefined)} />;\n }\n\n return <NativeErrorBoundary FallbackComponent={ErrorFallback}>{children}</NativeErrorBoundary>;\n};\n\nconst ErrorFallback = ({ error }: FallbackProps) => {\n const { name, message, stack } =\n error instanceof Error ? error : { name: 'Error', message: String(error), stack: undefined };\n return (\n <div role='alert' className='flex flex-col p-4 gap-4 overflow-auto'>\n <h1 className='text-xl text-red-500'>{name}</h1>\n <div className='text-lg'>{message}</div>\n {stack && <pre className='whitespace-pre-wrap text-sm text-subdued'>{stack}</pre>}\n </div>\n );\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;AAIA,cAAc;;;ACAd,OAAOA,SAASC,UAAmBC,WAAWC,cAAc;AAE5D,SAASC,cAA8B;AACvC,SAASC,aAAaC,yBAAyB;AAE/C,SAASC,8BAA8B;AACvC,SAASC,aAAa;AA8Bf,IAAM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AA;IAAoBC,mBAAmBH;KAAgBV,QAAAA;AACjE;AAEA,IAAMU,gBAAgB,CAAC,EAAET,MAAK,MAAiB;AAC7C,QAAM,EAAEnD,MAAMgE,SAASC,MAAK,IAC1Bd,iBAAiB3C,QAAQ2C,QAAQ;IAAEnD,MAAM;IAASgE,SAASE,OAAOf,KAAAA;IAAQc,OAAO9D;EAAU;AAC7F,SACE,gBAAAY,OAAA,cAACoD,OAAAA;IAAIC,MAAK;IAAQC,WAAU;KAC1B,gBAAAtD,OAAA,cAACuD,MAAAA;IAAGD,WAAU;KAAwBrE,IAAAA,GACtC,gBAAAe,OAAA,cAACoD,OAAAA;IAAIE,WAAU;KAAWL,OAAAA,GACzBC,SAAS,gBAAAlD,OAAA,cAACwD,OAAAA;IAAIF,WAAU;KAA4CJ,KAAAA,CAAAA;AAG3E;",
|
|
6
6
|
"names": ["React", "useState", "useEffect", "useRef", "Client", "TestBuilder", "performInvitation", "registerSignalsRuntime", "faker", "ClientRepeater", "props", "component", "Component", "controls", "Controls", "count", "types", "createIdentity", "createSpace", "onSpaceCreated", "useEffect", "registerSignalsRuntime", "clients", "setClients", "useState", "spaceKey", "setSpaceKey", "testBuilder", "useRef", "TestBuilder", "timeout", "setTimeout", "Array", "map", "_", "Client", "services", "current", "createLocalClientServices", "Promise", "all", "client", "initialize", "halo", "space", "spaces", "create", "name", "faker", "commerce", "productName", "key", "slice", "flatMap", "performInvitation", "host", "guest", "clearTimeout", "length", "index", "ClientProvider", "id", "args", "React", "createContext", "useContext", "useEffect", "useRef", "useState", "ErrorBoundary", "NativeErrorBoundary", "Trigger", "performInvitation", "TestBuilder", "raise", "log", "initializeClient", "client", "createIdentity", "createSpace", "onSpaceCreated", "onInitialized", "clientData", "halo", "identity", "get", "space", "spaceData", "spaces", "create", "name", "StoryClientContext", "createContext", "undefined", "useStoryClientData", "data", "useContext", "raise", "Error", "withClientProvider", "props", "Story", "setData", "useState", "handleInitialized", "React", "ErrorBoundary", "ClientProvider", "Provider", "value", "MultiClientContext", "id", "useMultiClient", "withMultiClientProvider", "numClients", "builder", "useRef", "TestBuilder", "hostRef", "spaceReady", "Trigger", "index", "log", "info", "current", "wake", "wait", "Promise", "all", "performInvitation", "host", "guest", "Array", "from", "length", "map", "_", "key", "services", "createLocalClientServices", "children", "error", "setError", "useEffect", "handleError", "event", "reason", "window", "addEventListener", "removeEventListener", "ErrorFallback", "resetErrorBoundary", "NativeErrorBoundary", "FallbackComponent", "message", "stack", "String", "div", "role", "className", "h1", "pre"]
|
|
7
7
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type Echo, type
|
|
1
|
+
import { type Echo, type ReactiveEchoObject, type FilterSource, type QueryOptions, type Space } from '@dxos/client/echo';
|
|
2
2
|
/**
|
|
3
3
|
* Create subscription.
|
|
4
4
|
*/
|
|
5
|
-
export declare const useQuery: <T extends
|
|
5
|
+
export declare const useQuery: <T extends ReactiveEchoObject<any>>(spaceOrEcho?: Space | Echo, filter?: FilterSource<T>, options?: QueryOptions, deps?: any[]) => T[];
|
|
6
6
|
//# sourceMappingURL=useQuery.d.ts.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { type Schema as S } from '@effect/schema';
|
|
2
1
|
import React, { type FC } from 'react';
|
|
3
2
|
import { Client, type PublicKey } from '@dxos/client';
|
|
3
|
+
import { type AbstractTypedObject } from '@dxos/echo-schema';
|
|
4
4
|
import { type WithClientProviderProps } from './withClientProvider';
|
|
5
5
|
export type ClientRepeatedComponentProps = {
|
|
6
6
|
id: number;
|
|
@@ -16,7 +16,7 @@ export type ClientRepeaterProps<P extends ClientRepeatedComponentProps> = {
|
|
|
16
16
|
controls?: FC<ClientRepeaterControlsProps>;
|
|
17
17
|
count?: number;
|
|
18
18
|
clients?: Client[];
|
|
19
|
-
types?:
|
|
19
|
+
types?: AbstractTypedObject[];
|
|
20
20
|
args?: Omit<P, 'id' | 'count'>;
|
|
21
21
|
} & Pick<WithClientProviderProps, 'createIdentity' | 'createSpace' | 'onSpaceCreated'>;
|
|
22
22
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ClientRepeater.d.ts","sourceRoot":"","sources":["../../../../src/testing/ClientRepeater.tsx"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"ClientRepeater.d.ts","sourceRoot":"","sources":["../../../../src/testing/ClientRepeater.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAAY,KAAK,EAAE,EAAqB,MAAM,OAAO,CAAC;AAEpE,OAAO,EAAE,MAAM,EAAE,KAAK,SAAS,EAAE,MAAM,cAAc,CAAC;AAEtD,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAI7D,OAAO,EAAE,KAAK,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAGpE,MAAM,MAAM,4BAA4B,GAAG;IAAE,EAAE,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,CAAC;AAE/F,MAAM,MAAM,2BAA2B,GAAG;IAAE,OAAO,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAGhE,MAAM,MAAM,mBAAmB,CAAC,CAAC,SAAS,4BAA4B,IAAI;IACxE,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,EAAE,CAAC,4BAA4B,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,EAAE,CAAC,2BAA2B,CAAC,CAAC;IAC3C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,KAAK,CAAC,EAAE,mBAAmB,EAAE,CAAC;IAC9B,IAAI,CAAC,EAAE,IAAI,CAAC,CAAC,EAAE,IAAI,GAAG,OAAO,CAAC,CAAC;CAChC,GAAG,IAAI,CAAC,uBAAuB,EAAE,gBAAgB,GAAG,aAAa,GAAG,gBAAgB,CAAC,CAAC;AAEvF;;;;GAIG;AAMH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,4BAA4B,SAAS,mBAAmB,CAAC,CAAC,CAAC,6BA2DnG,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-client",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2-main.f1adc9f",
|
|
4
4
|
"description": "React client API",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -77,40 +77,40 @@
|
|
|
77
77
|
},
|
|
78
78
|
"dependencies": {
|
|
79
79
|
"react-error-boundary": "^4.0.13",
|
|
80
|
-
"@dxos/async": "0.7.
|
|
81
|
-
"@dxos/client": "0.7.
|
|
82
|
-
"@dxos/
|
|
83
|
-
"@dxos/
|
|
84
|
-
"@dxos/
|
|
85
|
-
"@dxos/echo-
|
|
86
|
-
"@dxos/
|
|
87
|
-
"@dxos/
|
|
88
|
-
"@dxos/
|
|
89
|
-
"@dxos/
|
|
90
|
-
"@dxos/
|
|
91
|
-
"@dxos/react-hooks": "0.7.
|
|
92
|
-
"@dxos/util": "0.7.
|
|
80
|
+
"@dxos/async": "0.7.2-main.f1adc9f",
|
|
81
|
+
"@dxos/client": "0.7.2-main.f1adc9f",
|
|
82
|
+
"@dxos/config": "0.7.2-main.f1adc9f",
|
|
83
|
+
"@dxos/codec-protobuf": "0.7.2-main.f1adc9f",
|
|
84
|
+
"@dxos/echo-schema": "0.7.2-main.f1adc9f",
|
|
85
|
+
"@dxos/echo-signals": "0.7.2-main.f1adc9f",
|
|
86
|
+
"@dxos/debug": "0.7.2-main.f1adc9f",
|
|
87
|
+
"@dxos/invariant": "0.7.2-main.f1adc9f",
|
|
88
|
+
"@dxos/log": "0.7.2-main.f1adc9f",
|
|
89
|
+
"@dxos/protocols": "0.7.2-main.f1adc9f",
|
|
90
|
+
"@dxos/node-std": "0.7.2-main.f1adc9f",
|
|
91
|
+
"@dxos/react-hooks": "0.7.2-main.f1adc9f",
|
|
92
|
+
"@dxos/util": "0.7.2-main.f1adc9f"
|
|
93
93
|
},
|
|
94
94
|
"devDependencies": {
|
|
95
95
|
"@types/react": "~18.2.0",
|
|
96
96
|
"@types/react-dom": "~18.2.0",
|
|
97
97
|
"react": "~18.2.0",
|
|
98
98
|
"react-dom": "~18.2.0",
|
|
99
|
-
"@dxos/random": "0.7.
|
|
100
|
-
"@dxos/react-ui": "0.7.
|
|
101
|
-
"@dxos/react-ui
|
|
102
|
-
"@dxos/react-ui-theme": "0.7.
|
|
103
|
-
"@dxos/
|
|
104
|
-
"@dxos/
|
|
99
|
+
"@dxos/random": "0.7.2-main.f1adc9f",
|
|
100
|
+
"@dxos/react-ui-syntax-highlighter": "0.7.2-main.f1adc9f",
|
|
101
|
+
"@dxos/react-ui": "0.7.2-main.f1adc9f",
|
|
102
|
+
"@dxos/react-ui-theme": "0.7.2-main.f1adc9f",
|
|
103
|
+
"@dxos/test-utils": "0.7.2-main.f1adc9f",
|
|
104
|
+
"@dxos/storybook-utils": "0.7.2-main.f1adc9f"
|
|
105
105
|
},
|
|
106
106
|
"peerDependencies": {
|
|
107
107
|
"react": "~18.2.0",
|
|
108
108
|
"react-dom": "~18.2.0"
|
|
109
109
|
},
|
|
110
110
|
"optionalDependencies": {
|
|
111
|
-
"@dxos/
|
|
112
|
-
"@dxos/react-ui
|
|
113
|
-
"@dxos/
|
|
111
|
+
"@dxos/random": "0.7.2-main.f1adc9f",
|
|
112
|
+
"@dxos/react-ui": "0.7.2-main.f1adc9f",
|
|
113
|
+
"@dxos/react-ui-theme": "0.7.2-main.f1adc9f"
|
|
114
114
|
},
|
|
115
115
|
"publishConfig": {
|
|
116
116
|
"access": "public"
|
package/src/echo/useQuery.ts
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
Filter,
|
|
9
9
|
isSpace,
|
|
10
10
|
type Echo,
|
|
11
|
-
type
|
|
11
|
+
type ReactiveEchoObject,
|
|
12
12
|
type FilterSource,
|
|
13
13
|
type Query,
|
|
14
14
|
type QueryOptions,
|
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
* Create subscription.
|
|
20
20
|
*/
|
|
21
21
|
// TODO(burdon): Support typed operator filters (e.g., Note.filter(note => ...)).
|
|
22
|
-
export const useQuery = <T extends
|
|
22
|
+
export const useQuery = <T extends ReactiveEchoObject<any>>(
|
|
23
23
|
spaceOrEcho?: Space | Echo,
|
|
24
24
|
filter?: FilterSource<T>,
|
|
25
25
|
options?: QueryOptions,
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type Schema as S } from '@effect/schema';
|
|
6
5
|
import React, { useState, type FC, useEffect, useRef } from 'react';
|
|
7
6
|
|
|
8
7
|
import { Client, type PublicKey } from '@dxos/client';
|
|
9
8
|
import { TestBuilder, performInvitation } from '@dxos/client/testing';
|
|
9
|
+
import { type AbstractTypedObject } from '@dxos/echo-schema';
|
|
10
10
|
import { registerSignalsRuntime } from '@dxos/echo-signals/react';
|
|
11
11
|
import { faker } from '@dxos/random';
|
|
12
12
|
|
|
@@ -24,7 +24,7 @@ export type ClientRepeaterProps<P extends ClientRepeatedComponentProps> = {
|
|
|
24
24
|
controls?: FC<ClientRepeaterControlsProps>;
|
|
25
25
|
count?: number;
|
|
26
26
|
clients?: Client[];
|
|
27
|
-
types?:
|
|
27
|
+
types?: AbstractTypedObject[];
|
|
28
28
|
args?: Omit<P, 'id' | 'count'>;
|
|
29
29
|
} & Pick<WithClientProviderProps, 'createIdentity' | 'createSpace' | 'onSpaceCreated'>;
|
|
30
30
|
|