@dxos/react-client 0.7.4 → 0.7.5-feature-compute.4d9d99a

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/dist/lib/browser/{chunk-U4MCIYKN.mjs → chunk-Z6OJATVN.mjs} +58 -41
  2. package/dist/lib/browser/chunk-Z6OJATVN.mjs.map +7 -0
  3. package/dist/lib/browser/devtools/index.mjs +1 -1
  4. package/dist/lib/browser/echo/index.mjs +1 -1
  5. package/dist/lib/browser/halo/index.mjs +1 -1
  6. package/dist/lib/browser/index.mjs +1 -1
  7. package/dist/lib/browser/mesh/index.mjs +1 -1
  8. package/dist/lib/browser/meta.json +1 -1
  9. package/dist/lib/browser/testing/index.mjs +32 -33
  10. package/dist/lib/browser/testing/index.mjs.map +4 -4
  11. package/dist/lib/node/{chunk-UJLDNXPC.cjs → chunk-DITMVTAF.cjs} +61 -44
  12. package/dist/lib/node/chunk-DITMVTAF.cjs.map +7 -0
  13. package/dist/lib/node/devtools/index.cjs +2 -2
  14. package/dist/lib/node/echo/index.cjs +3 -3
  15. package/dist/lib/node/halo/index.cjs +5 -5
  16. package/dist/lib/node/index.cjs +12 -12
  17. package/dist/lib/node/mesh/index.cjs +2 -2
  18. package/dist/lib/node/meta.json +1 -1
  19. package/dist/lib/node/testing/index.cjs +61 -63
  20. package/dist/lib/node/testing/index.cjs.map +4 -4
  21. package/dist/lib/node-esm/{chunk-4J4SI7XJ.mjs → chunk-6QHTUQ4Z.mjs} +58 -41
  22. package/dist/lib/node-esm/chunk-6QHTUQ4Z.mjs.map +7 -0
  23. package/dist/lib/node-esm/devtools/index.mjs +1 -1
  24. package/dist/lib/node-esm/echo/index.mjs +1 -1
  25. package/dist/lib/node-esm/halo/index.mjs +1 -1
  26. package/dist/lib/node-esm/index.mjs +1 -1
  27. package/dist/lib/node-esm/mesh/index.mjs +1 -1
  28. package/dist/lib/node-esm/meta.json +1 -1
  29. package/dist/lib/node-esm/testing/index.mjs +32 -33
  30. package/dist/lib/node-esm/testing/index.mjs.map +4 -4
  31. package/dist/types/src/client/ClientProvider.d.ts.map +1 -1
  32. package/dist/types/src/testing/ClientRepeater.d.ts +2 -2
  33. package/dist/types/src/testing/ClientRepeater.d.ts.map +1 -1
  34. package/dist/types/src/testing/context.d.ts +7 -0
  35. package/dist/types/src/testing/context.d.ts.map +1 -0
  36. package/dist/types/src/testing/index.d.ts +1 -0
  37. package/dist/types/src/testing/index.d.ts.map +1 -1
  38. package/dist/types/src/testing/withClientProvider.d.ts +4 -8
  39. package/dist/types/src/testing/withClientProvider.d.ts.map +1 -1
  40. package/dist/types/tsconfig.tsbuildinfo +1 -0
  41. package/package.json +23 -23
  42. package/src/client/ClientProvider.tsx +26 -14
  43. package/src/testing/ClientRepeater.tsx +3 -3
  44. package/src/testing/context.tsx +19 -0
  45. package/src/testing/index.ts +1 -0
  46. package/src/testing/withClientProvider.tsx +37 -39
  47. package/tsconfig.json +61 -2
  48. package/dist/lib/browser/chunk-U4MCIYKN.mjs.map +0 -7
  49. package/dist/lib/node/chunk-UJLDNXPC.cjs.map +0 -7
  50. package/dist/lib/node-esm/chunk-4J4SI7XJ.mjs.map +0 -7
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 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 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 onIdentityCreated?: (props: { 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, onIdentityCreated, onInitialized }: InitializeProps,\n): Promise<StoryClientProps> => {\n const clientData = await onInitialized?.(client);\n\n let identityData: Record<string, any> | void = {};\n if (createIdentity || createSpace) {\n if (!client.halo.identity.get()) {\n await client.halo.createIdentity();\n identityData = await onIdentityCreated?.({ client });\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, ...identityData, ...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 onIdentityCreated,\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(\n await initializeClient(client, {\n createIdentity,\n createSpace,\n onSpaceCreated,\n onIdentityCreated,\n onInitialized,\n }),\n );\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 onIdentityCreated,\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 onIdentityCreated,\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,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iBAAiB,sBAAsBJ,WAAAA;AAC9C,WAAO,MAAMG,OAAOE,oBAAoB,sBAAsBL,WAAAA;EAChE,GAAG,CAAA,CAAE;AAEL,MAAIH,OAAO;AACT,WAAO,gBAAApC,OAAA,cAAC6C,eAAAA;MAAcT;MAAcU,oBAAoB,MAAMT,SAASjD,MAAAA;;EACzE;AAEA,SAAO,gBAAAY,OAAA,cAAC+C,qBAAAA;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
- "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", "onIdentityCreated", "onInitialized", "clientData", "identityData", "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"]
3
+ "sources": ["../../../../src/testing/index.ts", "../../../../src/testing/context.tsx", "../../../../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 './context';\nexport * from './ClientRepeater';\nexport * from './withClientProvider';\n", "//\n// Copyright 2024 DXOS.org\n//\n\nimport { createContext, useContext } from 'react';\n\nimport { type Space } from '@dxos/client/echo';\nimport { raise } from '@dxos/debug';\n\nexport type ClientStory = {\n space?: Space;\n};\n\n// TODO(wittjosiah): Add to multi-client as well.\nexport const ClientStory = createContext<ClientStory | undefined>(undefined);\n\nexport const useClientProvider = (): ClientStory => {\n return useContext(ClientStory) ?? raise(new Error('Missing ClientStory'));\n};\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 TypedObject } 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?: TypedObject[];\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 StoryContext, 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 { log } from '@dxos/log';\nimport { type MaybePromise } from '@dxos/util';\n\nimport { ClientStory } from './context';\nimport { ClientProvider, type ClientProviderProps } from '../client';\n\ntype InitializeProps = {\n createIdentity?: boolean;\n createSpace?: boolean;\n onInitialized?: (client: Client) => MaybePromise<void>;\n onIdentityCreated?: (props: { client: Client }) => MaybePromise<void>;\n // NOTE: context must be untyped until ClientRepeater is removed.\n onSpaceCreated?: (props: { client: Client; space: Space }, context: StoryContext | any) => MaybePromise<void>;\n};\n\n/**\n * Initialize client, identity and first space.\n */\nconst initializeClient = async (\n client: Client,\n { createIdentity, createSpace, onSpaceCreated, onIdentityCreated, onInitialized }: InitializeProps,\n context: StoryContext,\n): Promise<ClientStory> => {\n await onInitialized?.(client);\n\n if (createIdentity || createSpace) {\n if (!client.halo.identity.get()) {\n await client.halo.createIdentity();\n await onIdentityCreated?.({ client });\n }\n }\n\n let space: Space | undefined;\n if (createSpace) {\n space = await client.spaces.create({ name: 'Test Space' });\n await onSpaceCreated?.({ client, space }, context);\n }\n\n return { space };\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 onIdentityCreated,\n onInitialized,\n ...props\n}: WithClientProviderProps = {}): Decorator => {\n return (Story, context) => {\n const [data, setData] = useState<ClientStory>({});\n const handleInitialized = async (client: Client) => {\n const data = await initializeClient(\n client,\n {\n createIdentity,\n createSpace,\n onSpaceCreated,\n onIdentityCreated,\n onInitialized,\n },\n context,\n );\n\n setData(data);\n };\n\n return (\n <ErrorBoundary>\n <ClientProvider onInitialized={handleInitialized} {...props}>\n <ClientStory.Provider value={data}>\n <Story />\n </ClientStory.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 onIdentityCreated,\n onInitialized,\n ...props\n}: WithMultiClientProviderProps): Decorator => {\n return (Story, context) => {\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(\n client,\n {\n createIdentity,\n createSpace,\n onSpaceCreated,\n onIdentityCreated,\n onInitialized,\n },\n context,\n );\n\n spaceReady.current.wake(space);\n log.info('inviting', { index });\n } else {\n await initializeClient(client, { createIdentity, onInitialized }, context);\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,SAASA,eAAeC,kBAAkB;AAG1C,SAASC,aAAa;AAOf,IAAMC,cAAcC,8BAAuCC,MAAAA;AAE3D,IAAMC,oBAAoB,MAAA;AAC/B,SAAOC,WAAWJ,WAAAA,KAAgBK,MAAM,IAAIC,MAAM,qBAAA,CAAA;A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AAEA,SAAO,gBAAAlD,OAAA,cAACmD,qBAAAA;IAAoBC,mBAAmBJ;KAAgBV,QAAAA;AACjE;AAEA,IAAMU,gBAAgB,CAAC,EAAET,MAAK,MAAiB;AAC7C,QAAM,EAAE/C,MAAM6D,SAASC,MAAK,IAC1Bf,iBAAiBgB,QAAQhB,QAAQ;IAAE/C,MAAM;IAAS6D,SAASG,OAAOjB,KAAAA;IAAQe,OAAOJ;EAAU;AAC7F,SACE,gBAAAlD,OAAA,cAACyD,OAAAA;IAAIC,MAAK;IAAQC,WAAU;KAC1B,gBAAA3D,OAAA,cAAC4D,MAAAA;IAAGD,WAAU;KAAwBnE,IAAAA,GACtC,gBAAAQ,OAAA,cAACyD,OAAAA;IAAIE,WAAU;KAAWN,OAAAA,GACzBC,SAAS,gBAAAtD,OAAA,cAAC6D,OAAAA;IAAIF,WAAU;KAA4CL,KAAAA,CAAAA;AAG3E;",
6
+ "names": ["createContext", "useContext", "raise", "ClientStory", "createContext", "undefined", "useClientProvider", "useContext", "raise", "Error", "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", "log", "initializeClient", "client", "createIdentity", "createSpace", "onSpaceCreated", "onIdentityCreated", "onInitialized", "context", "halo", "identity", "get", "space", "spaces", "create", "name", "withClientProvider", "props", "Story", "data", "setData", "useState", "handleInitialized", "React", "ErrorBoundary", "ClientProvider", "ClientStory", "Provider", "value", "MultiClientContext", "createContext", "id", "useMultiClient", "useContext", "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", "undefined", "NativeErrorBoundary", "FallbackComponent", "message", "stack", "Error", "String", "div", "role", "className", "h1", "pre"]
7
7
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ClientProvider.d.ts","sourceRoot":"","sources":["../../../../src/client/ClientProvider.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,EAEZ,KAAK,iBAAiB,EACtB,KAAK,iBAAiB,EAIvB,MAAM,OAAO,CAAC;AAEf,OAAO,EAAE,MAAM,EAAE,KAAK,aAAa,EAAE,KAAK,sBAAsB,EAAgB,MAAM,cAAc,CAAC;AACrG,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,cAAc,CAAC;AAI3C,OAAO,EAAyB,KAAK,YAAY,EAAE,KAAK,QAAQ,EAAE,MAAM,YAAY,CAAC;AAErF,OAAO,EAAiB,KAAK,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAGnE;;GAEG;AACH,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,aAAa,EAAE,QAAQ,GAAG,UAAU,CAAC,GAC1E,IAAI,CAAC,kBAAkB,EAAE,QAAQ,CAAC,GAClC,iBAAiB,CAAC;IAChB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAE5C;;;;OAIG;IAEH,MAAM,CAAC,EAAE,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CA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AAC,CAAC,MAAM,CAAC,EAAE,MAAM,KAAK,YAAY,CAAC,sBAAsB,CAAC,CAAC;IAE/F;;OAEG;eACQ,iBAAiB,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAEzD;;;OAGG;qBACc,OAAO;IAExB;;OAEG;eACQ,OAAO;IAElB;;OAEG;oBACa,CAAC,MAAM,EAAE,MAAM,KAAK,YAAY,CAAC,IAAI,CAAC;;;4CAwHzD,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import React, { type FC } from 'react';
2
2
  import { Client, type PublicKey } from '@dxos/client';
3
- import { type AbstractTypedObject } from '@dxos/echo-schema';
3
+ import { type TypedObject } 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?: AbstractTypedObject[];
19
+ types?: TypedObject[];
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,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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,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,WAAW,EAAE,CAAC;IACtB,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"}
@@ -0,0 +1,7 @@
1
+ import { type Space } from '@dxos/client/echo';
2
+ export type ClientStory = {
3
+ space?: Space;
4
+ };
5
+ export declare const ClientStory: import("react").Context<ClientStory | undefined>;
6
+ export declare const useClientProvider: () => ClientStory;
7
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../../src/testing/context.tsx"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG/C,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,CAAC,EAAE,KAAK,CAAC;CACf,CAAC;AAGF,eAAO,MAAM,WAAW,kDAAoD,CAAC;AAE7E,eAAO,MAAM,iBAAiB,QAAO,WAEpC,CAAC"}
@@ -1,4 +1,5 @@
1
1
  export * from '@dxos/client/testing';
2
+ export * from './context';
2
3
  export * from './ClientRepeater';
3
4
  export * from './withClientProvider';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,sBAAsB,CAAC;AAErC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAIA,cAAc,sBAAsB,CAAC;AAErC,cAAc,WAAW,CAAC;AAC1B,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC"}
@@ -1,4 +1,4 @@
1
- import { type Decorator } from '@storybook/react';
1
+ import { type StoryContext, type Decorator } from '@storybook/react';
2
2
  import { type Client } from '@dxos/client';
3
3
  import { type Space } from '@dxos/client/echo';
4
4
  import { type MaybePromise } from '@dxos/util';
@@ -6,19 +6,15 @@ import { type ClientProviderProps } from '../client';
6
6
  type InitializeProps = {
7
7
  createIdentity?: boolean;
8
8
  createSpace?: boolean;
9
- onInitialized?: (client: Client) => MaybePromise<Record<string, any> | void>;
9
+ onInitialized?: (client: Client) => MaybePromise<void>;
10
10
  onIdentityCreated?: (props: {
11
11
  client: Client;
12
- }) => MaybePromise<Record<string, any> | void>;
12
+ }) => MaybePromise<void>;
13
13
  onSpaceCreated?: (props: {
14
14
  client: Client;
15
15
  space: Space;
16
- }) => MaybePromise<Record<string, any> | void>;
16
+ }, context: StoryContext | any) => MaybePromise<void>;
17
17
  };
18
- type StoryClientProps<T extends Record<string, any> = Record<string, unknown>> = T & {
19
- space?: Space;
20
- };
21
- export declare const useStoryClientData: <T extends Record<string, any> = Record<string, unknown>>() => StoryClientProps<T>;
22
18
  export type WithClientProviderProps = InitializeProps & Omit<ClientProviderProps, 'onInitialized'>;
23
19
  /**
24
20
  * Decorator that provides the client context.
@@ -1 +1 @@
1
- {"version":3,"file":"withClientProvider.d.ts","sourceRoot":"","s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YAAY,GAAG,GAAG,KAAK,YAAY,CAAC,IAAI,CAAC,CAAC;CAC/G,CAAC;AA4BF,MAAM,MAAM,uBAAuB,GAAG,eAAe,GAAG,IAAI,CAAC,mBAAmB,EAAE,eAAe,CAAC,CAAC;AAEnG;;GAEG;AACH,eAAO,MAAM,kBAAkB,iGAO5B,uBAAuB,KAAQ,SA6BjC,CAAC;AAKF,MAAM,MAAM,4BAA4B,GAAG,eAAe,GACxD,IAAI,CAAC,mBAAmB,EAAE,eAAe,CAAC,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AAIvE,eAAO,MAAM,cAAc;QAFoB,MAAM;CAEa,CAAC;AAEnE;;;;GAIG;AACH,eAAO,MAAM,uBAAuB,4GAQjC,4BAA4B,KAAG,SAsDjC,CAAC"}
@@ -0,0 +1 @@
1
+ {"version":"5.7.2"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-client",
3
- "version": "0.7.4",
3
+ "version": "0.7.5-feature-compute.4d9d99a",
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.4",
81
- "@dxos/client": "0.7.4",
82
- "@dxos/codec-protobuf": "0.7.4",
83
- "@dxos/debug": "0.7.4",
84
- "@dxos/echo-schema": "0.7.4",
85
- "@dxos/config": "0.7.4",
86
- "@dxos/echo-signals": "0.7.4",
87
- "@dxos/invariant": "0.7.4",
88
- "@dxos/node-std": "0.7.4",
89
- "@dxos/log": "0.7.4",
90
- "@dxos/protocols": "0.7.4",
91
- "@dxos/react-hooks": "0.7.4",
92
- "@dxos/util": "0.7.4"
80
+ "@dxos/async": "0.7.5-feature-compute.4d9d99a",
81
+ "@dxos/client": "0.7.5-feature-compute.4d9d99a",
82
+ "@dxos/config": "0.7.5-feature-compute.4d9d99a",
83
+ "@dxos/codec-protobuf": "0.7.5-feature-compute.4d9d99a",
84
+ "@dxos/debug": "0.7.5-feature-compute.4d9d99a",
85
+ "@dxos/echo-schema": "0.7.5-feature-compute.4d9d99a",
86
+ "@dxos/invariant": "0.7.5-feature-compute.4d9d99a",
87
+ "@dxos/echo-signals": "0.7.5-feature-compute.4d9d99a",
88
+ "@dxos/log": "0.7.5-feature-compute.4d9d99a",
89
+ "@dxos/node-std": "0.7.5-feature-compute.4d9d99a",
90
+ "@dxos/protocols": "0.7.5-feature-compute.4d9d99a",
91
+ "@dxos/util": "0.7.5-feature-compute.4d9d99a",
92
+ "@dxos/react-hooks": "0.7.5-feature-compute.4d9d99a"
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/react-ui": "0.7.4",
100
- "@dxos/random": "0.7.4",
101
- "@dxos/storybook-utils": "0.7.4",
102
- "@dxos/react-ui-syntax-highlighter": "0.7.4",
103
- "@dxos/test-utils": "0.7.4",
104
- "@dxos/react-ui-theme": "0.7.4"
99
+ "@dxos/react-ui": "0.7.5-feature-compute.4d9d99a",
100
+ "@dxos/react-ui-syntax-highlighter": "0.7.5-feature-compute.4d9d99a",
101
+ "@dxos/react-ui-theme": "0.7.5-feature-compute.4d9d99a",
102
+ "@dxos/random": "0.7.5-feature-compute.4d9d99a",
103
+ "@dxos/storybook-utils": "0.7.5-feature-compute.4d9d99a",
104
+ "@dxos/test-utils": "0.7.5-feature-compute.4d9d99a"
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/random": "0.7.4",
112
- "@dxos/react-ui": "0.7.4",
113
- "@dxos/react-ui-theme": "0.7.4"
111
+ "@dxos/random": "0.7.5-feature-compute.4d9d99a",
112
+ "@dxos/react-ui": "0.7.5-feature-compute.4d9d99a",
113
+ "@dxos/react-ui-theme": "0.7.5-feature-compute.4d9d99a"
114
114
  },
115
115
  "publishConfig": {
116
116
  "access": "public"
@@ -126,9 +126,14 @@ export const ClientProvider = forwardRef<Client | undefined, ClientProviderProps
126
126
 
127
127
  // Create and/or initialize client.
128
128
  useEffect(() => {
129
+ let disposed = false;
129
130
  const initialize = async (client: Client) => {
130
131
  if (!client.initialized) {
131
- await client.initialize().catch(setError);
132
+ await client.initialize().catch((err) => {
133
+ if (!disposed) {
134
+ setError(err);
135
+ }
136
+ });
132
137
  log('client ready');
133
138
  await onInitialized?.(client);
134
139
  log('initialization complete');
@@ -143,24 +148,31 @@ export const ClientProvider = forwardRef<Client | undefined, ClientProviderProps
143
148
 
144
149
  let client: Client;
145
150
  const t = setTimeout(async () => {
146
- if (clientProvider) {
147
- // Asynchronously request client.
148
- client = await getAsyncProviderValue(clientProvider);
149
- await initialize(client);
150
- } else {
151
- // Asynchronously construct client (config may be undefined).
152
- const config = await getAsyncProviderValue(configProvider);
153
- log('resolved config', { config });
154
- const services = await getAsyncProviderValue(servicesProvider, config);
155
- log('created services', { services });
156
- client = new Client({ config, services, ...options });
157
- log('created client');
158
- await initialize(client);
151
+ try {
152
+ if (clientProvider) {
153
+ // Asynchronously request client.
154
+ client = await getAsyncProviderValue(clientProvider);
155
+ await initialize(client);
156
+ } else {
157
+ // Asynchronously construct client (config may be undefined).
158
+ const config = await getAsyncProviderValue(configProvider);
159
+ log('resolved config', { config });
160
+ const services = await getAsyncProviderValue(servicesProvider, config);
161
+ log('created services', { services });
162
+ client = new Client({ config, services, ...options });
163
+ log('created client');
164
+ await initialize(client);
165
+ }
166
+ } catch (err) {
167
+ if (!disposed) {
168
+ log.catch(err);
169
+ }
159
170
  }
160
171
  });
161
172
 
162
173
  return () => {
163
174
  log('clean up');
175
+ disposed = true;
164
176
  clearTimeout(t);
165
177
  void client
166
178
  ?.destroy()
@@ -6,7 +6,7 @@ import React, { useState, type FC, useEffect, useRef } from 'react';
6
6
 
7
7
  import { Client, type PublicKey } from '@dxos/client';
8
8
  import { TestBuilder, performInvitation } from '@dxos/client/testing';
9
- import { type AbstractTypedObject } from '@dxos/echo-schema';
9
+ import { type TypedObject } 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?: AbstractTypedObject[];
27
+ types?: TypedObject[];
28
28
  args?: Omit<P, 'id' | 'count'>;
29
29
  } & Pick<WithClientProviderProps, 'createIdentity' | 'createSpace' | 'onSpaceCreated'>;
30
30
 
@@ -71,7 +71,7 @@ export const ClientRepeater = <P extends ClientRepeatedComponentProps>(props: Cl
71
71
  const client = clients[0];
72
72
  const space = await client.spaces.create({ name: faker.commerce.productName() });
73
73
  setSpaceKey(space.key);
74
- await onSpaceCreated?.({ client, space });
74
+ await onSpaceCreated?.({ client, space }, {});
75
75
  await Promise.all(
76
76
  clients.slice(1).flatMap((client) => performInvitation({ host: space, guest: client.spaces })),
77
77
  );
@@ -0,0 +1,19 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { createContext, useContext } from 'react';
6
+
7
+ import { type Space } from '@dxos/client/echo';
8
+ import { raise } from '@dxos/debug';
9
+
10
+ export type ClientStory = {
11
+ space?: Space;
12
+ };
13
+
14
+ // TODO(wittjosiah): Add to multi-client as well.
15
+ export const ClientStory = createContext<ClientStory | undefined>(undefined);
16
+
17
+ export const useClientProvider = (): ClientStory => {
18
+ return useContext(ClientStory) ?? raise(new Error('Missing ClientStory'));
19
+ };
@@ -4,5 +4,6 @@
4
4
 
5
5
  export * from '@dxos/client/testing';
6
6
 
7
+ export * from './context';
7
8
  export * from './ClientRepeater';
8
9
  export * from './withClientProvider';
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { type Decorator } from '@storybook/react';
5
+ import { type StoryContext, type Decorator } from '@storybook/react';
6
6
  import React, { createContext, type PropsWithChildren, useContext, useEffect, useRef, useState } from 'react';
7
7
  import { type FallbackProps, ErrorBoundary as NativeErrorBoundary } from 'react-error-boundary';
8
8
 
@@ -10,18 +10,19 @@ import { Trigger } from '@dxos/async';
10
10
  import { type Client } from '@dxos/client';
11
11
  import { type Space } from '@dxos/client/echo';
12
12
  import { performInvitation, TestBuilder } from '@dxos/client/testing';
13
- import { raise } from '@dxos/debug';
14
13
  import { log } from '@dxos/log';
15
14
  import { type MaybePromise } from '@dxos/util';
16
15
 
16
+ import { ClientStory } from './context';
17
17
  import { ClientProvider, type ClientProviderProps } from '../client';
18
18
 
19
19
  type InitializeProps = {
20
20
  createIdentity?: boolean;
21
21
  createSpace?: boolean;
22
- onInitialized?: (client: Client) => MaybePromise<Record<string, any> | void>;
23
- onIdentityCreated?: (props: { client: Client }) => MaybePromise<Record<string, any> | void>;
24
- onSpaceCreated?: (props: { client: Client; space: Space }) => MaybePromise<Record<string, any> | void>;
22
+ onInitialized?: (client: Client) => MaybePromise<void>;
23
+ onIdentityCreated?: (props: { client: Client }) => MaybePromise<void>;
24
+ // NOTE: context must be untyped until ClientRepeater is removed.
25
+ onSpaceCreated?: (props: { client: Client; space: Space }, context: StoryContext | any) => MaybePromise<void>;
25
26
  };
26
27
 
27
28
  /**
@@ -30,35 +31,24 @@ type InitializeProps = {
30
31
  const initializeClient = async (
31
32
  client: Client,
32
33
  { createIdentity, createSpace, onSpaceCreated, onIdentityCreated, onInitialized }: InitializeProps,
33
- ): Promise<StoryClientProps> => {
34
- const clientData = await onInitialized?.(client);
34
+ context: StoryContext,
35
+ ): Promise<ClientStory> => {
36
+ await onInitialized?.(client);
35
37
 
36
- let identityData: Record<string, any> | void = {};
37
38
  if (createIdentity || createSpace) {
38
39
  if (!client.halo.identity.get()) {
39
40
  await client.halo.createIdentity();
40
- identityData = await onIdentityCreated?.({ client });
41
+ await onIdentityCreated?.({ client });
41
42
  }
42
43
  }
43
44
 
44
45
  let space: Space | undefined;
45
- let spaceData: Record<string, any> | void = {};
46
46
  if (createSpace) {
47
47
  space = await client.spaces.create({ name: 'Test Space' });
48
- spaceData = await onSpaceCreated?.({ client, space });
48
+ await onSpaceCreated?.({ client, space }, context);
49
49
  }
50
50
 
51
- return { space, ...clientData, ...identityData, ...spaceData };
52
- };
53
-
54
- type StoryClientProps<T extends Record<string, any> = Record<string, unknown>> = T & { space?: Space };
55
-
56
- // TODO(wittjosiah): Add to multi-client as well.
57
- const StoryClientContext = createContext<StoryClientProps | undefined>(undefined);
58
-
59
- export const useStoryClientData = <T extends Record<string, any> = Record<string, unknown>>() => {
60
- const data = useContext(StoryClientContext) ?? raise(new Error('Missing withClientProvider decorator.'));
61
- return data as StoryClientProps<T>;
51
+ return { space };
62
52
  };
63
53
 
64
54
  export type WithClientProviderProps = InitializeProps & Omit<ClientProviderProps, 'onInitialized'>;
@@ -74,27 +64,30 @@ export const withClientProvider = ({
74
64
  onInitialized,
75
65
  ...props
76
66
  }: WithClientProviderProps = {}): Decorator => {
77
- return (Story) => {
78
- const [data, setData] = useState<StoryClientProps>({});
79
-
67
+ return (Story, context) => {
68
+ const [data, setData] = useState<ClientStory>({});
80
69
  const handleInitialized = async (client: Client) => {
81
- setData(
82
- await initializeClient(client, {
70
+ const data = await initializeClient(
71
+ client,
72
+ {
83
73
  createIdentity,
84
74
  createSpace,
85
75
  onSpaceCreated,
86
76
  onIdentityCreated,
87
77
  onInitialized,
88
- }),
78
+ },
79
+ context,
89
80
  );
81
+
82
+ setData(data);
90
83
  };
91
84
 
92
85
  return (
93
86
  <ErrorBoundary>
94
87
  <ClientProvider onInitialized={handleInitialized} {...props}>
95
- <StoryClientContext.Provider value={data}>
88
+ <ClientStory.Provider value={data}>
96
89
  <Story />
97
- </StoryClientContext.Provider>
90
+ </ClientStory.Provider>
98
91
  </ClientProvider>
99
92
  </ErrorBoundary>
100
93
  );
@@ -125,7 +118,7 @@ export const withMultiClientProvider = ({
125
118
  onInitialized,
126
119
  ...props
127
120
  }: WithMultiClientProviderProps): Decorator => {
128
- return (Story) => {
121
+ return (Story, context) => {
129
122
  const builder = useRef(new TestBuilder());
130
123
  const hostRef = useRef<Client>();
131
124
  const spaceReady = useRef(new Trigger<Space | undefined>());
@@ -137,17 +130,22 @@ export const withMultiClientProvider = ({
137
130
  if (createSpace) {
138
131
  if (!hostRef.current) {
139
132
  hostRef.current = client;
140
- const { space } = await initializeClient(client, {
141
- createIdentity,
142
- createSpace,
143
- onSpaceCreated,
144
- onIdentityCreated,
145
- onInitialized,
146
- });
133
+ const { space } = await initializeClient(
134
+ client,
135
+ {
136
+ createIdentity,
137
+ createSpace,
138
+ onSpaceCreated,
139
+ onIdentityCreated,
140
+ onInitialized,
141
+ },
142
+ context,
143
+ );
144
+
147
145
  spaceReady.current.wake(space);
148
146
  log.info('inviting', { index });
149
147
  } else {
150
- await initializeClient(client, { createIdentity, onInitialized });
148
+ await initializeClient(client, { createIdentity, onInitialized }, context);
151
149
  const space = await spaceReady.current.wait();
152
150
  if (space) {
153
151
  log.info('joining', { index });
package/tsconfig.json CHANGED
@@ -6,11 +6,70 @@
6
6
  "DOM",
7
7
  "ESNext"
8
8
  ],
9
- "module": "ESNext"
9
+ "module": "ESNext",
10
+ "outDir": "./dist/types"
10
11
  },
11
12
  "include": [
12
13
  "playwright",
13
14
  "src"
14
15
  ],
15
- "references": []
16
+ "references": [
17
+ {
18
+ "path": "../../common/async"
19
+ },
20
+ {
21
+ "path": "../../common/codec-protobuf"
22
+ },
23
+ {
24
+ "path": "../../common/debug"
25
+ },
26
+ {
27
+ "path": "../../common/invariant"
28
+ },
29
+ {
30
+ "path": "../../common/log"
31
+ },
32
+ {
33
+ "path": "../../common/node-std"
34
+ },
35
+ {
36
+ "path": "../../common/random"
37
+ },
38
+ {
39
+ "path": "../../common/storybook-utils"
40
+ },
41
+ {
42
+ "path": "../../common/test-utils"
43
+ },
44
+ {
45
+ "path": "../../common/util"
46
+ },
47
+ {
48
+ "path": "../../core/echo/echo-schema"
49
+ },
50
+ {
51
+ "path": "../../core/echo/echo-signals"
52
+ },
53
+ {
54
+ "path": "../../core/protocols"
55
+ },
56
+ {
57
+ "path": "../../ui/primitives/react-hooks"
58
+ },
59
+ {
60
+ "path": "../../ui/react-ui"
61
+ },
62
+ {
63
+ "path": "../../ui/react-ui-syntax-highlighter"
64
+ },
65
+ {
66
+ "path": "../../ui/react-ui-theme"
67
+ },
68
+ {
69
+ "path": "../client"
70
+ },
71
+ {
72
+ "path": "../config"
73
+ }
74
+ ]
16
75
  }