@dxos/plugin-debug 0.8.0 → 0.8.1-main.013e445

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 (74) hide show
  1. package/dist/lib/browser/{DebugApp-LQHFFK3Y.mjs → DebugApp-7PFYN52J.mjs} +30 -23
  2. package/dist/lib/browser/{DebugApp-LQHFFK3Y.mjs.map → DebugApp-7PFYN52J.mjs.map} +4 -4
  3. package/dist/lib/browser/{SpaceGenerator-SPEJBGP7.mjs → SpaceGenerator-XMWQDHXY.mjs} +3 -3
  4. package/dist/lib/browser/{SpaceGenerator-SPEJBGP7.mjs.map → SpaceGenerator-XMWQDHXY.mjs.map} +1 -1
  5. package/dist/lib/browser/{app-graph-builder-5STXPSZJ.mjs → app-graph-builder-EJHONTKA.mjs} +87 -29
  6. package/dist/lib/browser/{app-graph-builder-5STXPSZJ.mjs.map → app-graph-builder-EJHONTKA.mjs.map} +3 -3
  7. package/dist/lib/browser/{chunk-Y4ZZEHUN.mjs → chunk-F2R7TJCJ.mjs} +2 -2
  8. package/dist/lib/browser/{chunk-Y4ZZEHUN.mjs.map → chunk-F2R7TJCJ.mjs.map} +3 -3
  9. package/dist/lib/browser/{chunk-EF3UVAVI.mjs → chunk-RORUXVAC.mjs} +1 -1
  10. package/dist/lib/browser/chunk-RORUXVAC.mjs.map +7 -0
  11. package/dist/lib/browser/index.mjs +7 -6
  12. package/dist/lib/browser/index.mjs.map +2 -2
  13. package/dist/lib/browser/meta.json +1 -1
  14. package/dist/lib/browser/{react-context-TCD3MNIT.mjs → react-context-ZRLN5KUI.mjs} +2 -2
  15. package/dist/lib/browser/{react-surface-GLOHHHOD.mjs → react-surface-5NDFGKVB.mjs} +41 -24
  16. package/dist/lib/browser/react-surface-5NDFGKVB.mjs.map +7 -0
  17. package/dist/lib/browser/{settings-XWFV3P44.mjs → settings-R47ZDKXO.mjs} +5 -5
  18. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +1 -1
  19. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  20. package/dist/types/src/capabilities/react-surface.d.ts.map +1 -1
  21. package/dist/types/src/components/Container.d.ts +2 -2
  22. package/dist/types/src/components/Container.d.ts.map +1 -1
  23. package/dist/types/src/components/DebugObjectPanel.d.ts +2 -1
  24. package/dist/types/src/components/DebugObjectPanel.d.ts.map +1 -1
  25. package/dist/types/src/components/DebugSettings.d.ts +2 -1
  26. package/dist/types/src/components/DebugSettings.d.ts.map +1 -1
  27. package/dist/types/src/components/DebugStatus.d.ts +2 -1
  28. package/dist/types/src/components/DebugStatus.d.ts.map +1 -1
  29. package/dist/types/src/components/SpaceGenerator/SchemaTable.d.ts +2 -1
  30. package/dist/types/src/components/SpaceGenerator/SchemaTable.d.ts.map +1 -1
  31. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts +2 -1
  32. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts.map +1 -1
  33. package/dist/types/src/components/Wireframe.d.ts +2 -1
  34. package/dist/types/src/components/Wireframe.d.ts.map +1 -1
  35. package/dist/types/src/components/index.d.ts +1 -5
  36. package/dist/types/src/components/index.d.ts.map +1 -1
  37. package/dist/types/src/meta.d.ts +2 -9
  38. package/dist/types/src/meta.d.ts.map +1 -1
  39. package/dist/types/src/translations.d.ts +1 -0
  40. package/dist/types/src/translations.d.ts.map +1 -1
  41. package/dist/types/src/types.d.ts +1 -0
  42. package/dist/types/src/types.d.ts.map +1 -1
  43. package/package.json +49 -49
  44. package/src/capabilities/app-graph-builder.ts +53 -15
  45. package/src/capabilities/react-surface.tsx +31 -25
  46. package/src/components/SpaceGenerator/SchemaTable.tsx +1 -1
  47. package/src/components/SpaceGenerator/SpaceGenerator.tsx +1 -1
  48. package/src/components/index.ts +0 -1
  49. package/src/meta.ts +2 -2
  50. package/src/translations.ts +1 -0
  51. package/src/types.ts +1 -0
  52. package/dist/lib/browser/DebugSpace-EBJYT5JG.mjs +0 -277
  53. package/dist/lib/browser/DebugSpace-EBJYT5JG.mjs.map +0 -7
  54. package/dist/lib/browser/chunk-EF3UVAVI.mjs.map +0 -7
  55. package/dist/lib/browser/chunk-GSJS3HEM.mjs +0 -15
  56. package/dist/lib/browser/chunk-GSJS3HEM.mjs.map +0 -7
  57. package/dist/lib/browser/react-surface-GLOHHHOD.mjs.map +0 -7
  58. package/dist/types/src/components/DebugSpace/DebugSpace.d.ts +0 -8
  59. package/dist/types/src/components/DebugSpace/DebugSpace.d.ts.map +0 -1
  60. package/dist/types/src/components/DebugSpace/DebugSpace.stories.d.ts +0 -6
  61. package/dist/types/src/components/DebugSpace/DebugSpace.stories.d.ts.map +0 -1
  62. package/dist/types/src/components/DebugSpace/ObjectCreator.d.ts +0 -14
  63. package/dist/types/src/components/DebugSpace/ObjectCreator.d.ts.map +0 -1
  64. package/dist/types/src/components/DebugSpace/ObjectCreator.stories.d.ts +0 -6
  65. package/dist/types/src/components/DebugSpace/ObjectCreator.stories.d.ts.map +0 -1
  66. package/dist/types/src/components/DebugSpace/index.d.ts +0 -3
  67. package/dist/types/src/components/DebugSpace/index.d.ts.map +0 -1
  68. package/src/components/DebugSpace/DebugSpace.stories.tsx +0 -46
  69. package/src/components/DebugSpace/DebugSpace.tsx +0 -183
  70. package/src/components/DebugSpace/ObjectCreator.stories.tsx +0 -51
  71. package/src/components/DebugSpace/ObjectCreator.tsx +0 -100
  72. package/src/components/DebugSpace/index.ts +0 -7
  73. /package/dist/lib/browser/{react-context-TCD3MNIT.mjs.map → react-context-ZRLN5KUI.mjs.map} +0 -0
  74. /package/dist/lib/browser/{settings-XWFV3P44.mjs.map → settings-R47ZDKXO.mjs.map} +0 -0
@@ -1,183 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import React, { type FC, useContext, useMemo, useState } from 'react';
6
-
7
- import { createSpaceObjectGenerator } from '@dxos/echo-generator';
8
- import { type ReactiveObject } from '@dxos/live-object';
9
- import { DocumentType } from '@dxos/plugin-markdown/types';
10
- import { Invitation } from '@dxos/protocols/proto/dxos/client/services';
11
- import { faker } from '@dxos/random';
12
- import { useClient } from '@dxos/react-client';
13
- import { Filter, type Space, useSpaceInvitation } from '@dxos/react-client/echo';
14
- import { InvitationEncoder } from '@dxos/react-client/invitations';
15
- import { useAsyncEffect } from '@dxos/react-hooks';
16
- import { Icon, IconButton, Input, type IconProps, type TextInputProps, Toolbar, useFileDownload } from '@dxos/react-ui';
17
- import { safeParseInt } from '@dxos/util';
18
-
19
- import { ObjectCreator } from './ObjectCreator';
20
- import { DebugContext } from '../../types';
21
- import { Container } from '../Container';
22
-
23
- const DEFAULT_COUNT = 100;
24
- const DEFAULT_PERIOD = 500;
25
- const DEFAULT_JITTER = 50;
26
-
27
- const useRefresh = (): [any, () => void] => {
28
- const [update, setUpdate] = useState({});
29
- return [update, () => setUpdate({})];
30
- };
31
-
32
- const CustomInput = ({ icon, ...props }: Pick<IconProps, 'icon'> & TextInputProps) => {
33
- return (
34
- <div role='none' className='relative'>
35
- <Input.Root>
36
- <Input.TextInput classNames='w-[100px] text-right pie-[22px]' size={5} {...props} />
37
- </Input.Root>
38
- <Icon icon={icon} size={3} classNames='absolute inline-end-1 block-start-1 mt-[6px]' />
39
- </div>
40
- );
41
- };
42
-
43
- export const DebugSpace: FC<{
44
- space: Space;
45
- onAddObjects?: (objects: ReactiveObject<any>[]) => void;
46
- }> = ({ space, onAddObjects }) => {
47
- const { connect } = useSpaceInvitation(space?.key);
48
- const client = useClient();
49
- const [data, setData] = useState<any>({});
50
-
51
- const [update, handleUpdate] = useRefresh();
52
- useAsyncEffect(
53
- async (isMounted) => {
54
- const data = await client.diagnostics({ truncate: true });
55
- if (isMounted()) {
56
- setData(
57
- data?.diagnostics?.spaces?.find(({ key }: any) => {
58
- return space.key.toHex().startsWith(key);
59
- }),
60
- );
61
- }
62
- },
63
- [space, update],
64
- );
65
-
66
- const download = useFileDownload();
67
- const handleDownload = async () => {
68
- download(
69
- new Blob([JSON.stringify(data, undefined, 2)], { type: 'text/plain' }),
70
- `${new Date().toISOString().replace(/\W/g, '-')}.json`,
71
- );
72
- };
73
-
74
- const [mutationCount, setMutationCount] = useState(String(DEFAULT_COUNT));
75
- const [mutationInterval, setMutationInterval] = useState(String(DEFAULT_PERIOD));
76
- const [mutationJitter, setMutationJitter] = useState(String(DEFAULT_JITTER));
77
-
78
- const generator = useMemo(() => createSpaceObjectGenerator(space), [space]);
79
-
80
- // TODO(burdon): Note: this is shared across all spaces!
81
- const { running, start, stop } = useContext(DebugContext);
82
- const handleToggleRunning = () => {
83
- if (running) {
84
- stop();
85
- handleUpdate();
86
- } else {
87
- start(
88
- async () => {
89
- const { objects } = await space.db.query(Filter.schema(DocumentType)).run();
90
- if (objects.length) {
91
- const object = faker.helpers.arrayElement(objects);
92
- await generator.mutateObject(object, { count: 10, mutationSize: 10, maxContentLength: 1000 });
93
- }
94
- },
95
- {
96
- count: safeParseInt(mutationCount) ?? 0,
97
- interval: safeParseInt(mutationInterval) ?? 0,
98
- jitter: safeParseInt(mutationJitter) ?? 0,
99
- },
100
- );
101
- }
102
- };
103
-
104
- const handleCreateInvitation = () => {
105
- const invitation = space.share({
106
- type: Invitation.Type.INTERACTIVE,
107
- authMethod: Invitation.AuthMethod.NONE,
108
- multiUse: true,
109
- });
110
-
111
- // TODO(burdon): Refactor.
112
- // TODO(burdon): Unsubscribe?
113
- connect(invitation);
114
- const code = InvitationEncoder.encode(invitation.get());
115
- new URL(window.origin).searchParams.set('spaceInvitationCode', code);
116
- const url = `${window.origin}?spaceInvitationCode=${code}`;
117
- void navigator.clipboard.writeText(url);
118
- };
119
-
120
- const handleCreateEpoch = async () => {
121
- await space.internal.createEpoch();
122
- handleUpdate();
123
- };
124
-
125
- return (
126
- <Container
127
- toolbar={
128
- <Toolbar.Root classNames='p-1'>
129
- <CustomInput
130
- icon='ph--flag--regular'
131
- autoComplete='off'
132
- placeholder='Count'
133
- value={mutationCount}
134
- onChange={({ target: { value } }) => setMutationCount(value)}
135
- />
136
- <CustomInput
137
- icon='ph--timer--regular'
138
- autoComplete='off'
139
- placeholder='Interval'
140
- value={mutationInterval}
141
- onChange={({ target: { value } }) => setMutationInterval(value)}
142
- />
143
- <CustomInput
144
- icon='ph--plus-minus--regular'
145
- autoComplete='off'
146
- placeholder='Jitter'
147
- value={mutationJitter}
148
- onChange={({ target: { value } }) => setMutationJitter(value)}
149
- />
150
-
151
- <IconButton
152
- icon={running ? 'ph--pause-circle--regular' : 'ph--play-circle--regular'}
153
- iconOnly
154
- label='Start/stop'
155
- size={5}
156
- onClick={handleToggleRunning}
157
- />
158
- <IconButton icon='ph--arrow-clockwise--regular' iconOnly label='Refresh' size={5} onClick={handleUpdate} />
159
- <IconButton icon='ph--download-simple--regular' iconOnly label='Download' size={5} onClick={handleDownload} />
160
-
161
- <Toolbar.Separator variant='gap' />
162
- <IconButton
163
- icon='ph--flag-pennant--regular'
164
- iconOnly
165
- label='Create epoch'
166
- size={5}
167
- onClick={handleCreateEpoch}
168
- />
169
- <IconButton
170
- icon='ph--user-circle-plus--regular'
171
- iconOnly
172
- iconClassNames='text-blue-500'
173
- label='Create Invitation'
174
- size={5}
175
- onClick={handleCreateInvitation}
176
- />
177
- </Toolbar.Root>
178
- }
179
- >
180
- <ObjectCreator space={space} onAddObjects={onAddObjects} />
181
- </Container>
182
- );
183
- };
@@ -1,51 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import '@dxos-theme';
6
-
7
- import { type Meta } from '@storybook/react';
8
- import React from 'react';
9
-
10
- import { createSpaceObjectGenerator } from '@dxos/echo-generator';
11
- import { log } from '@dxos/log';
12
- import { useSpaces } from '@dxos/react-client/echo';
13
- import { withClientProvider } from '@dxos/react-client/testing';
14
- import { useAsyncEffect } from '@dxos/react-hooks';
15
- import { render, withLayout, withTheme } from '@dxos/storybook-utils';
16
-
17
- import { ObjectCreator, type ObjectCreatorProps } from './ObjectCreator';
18
-
19
- const DefaultStory = () => {
20
- const [space] = useSpaces();
21
- useAsyncEffect(async () => {
22
- if (space) {
23
- const generator = createSpaceObjectGenerator(space);
24
- await generator.addSchemas();
25
- }
26
- }, [space]);
27
-
28
- const handleCreate: ObjectCreatorProps['onAddObjects'] = (objects) => {
29
- log.info('created', { objects });
30
- };
31
-
32
- if (!space) {
33
- return null;
34
- }
35
-
36
- return <ObjectCreator space={space} onAddObjects={handleCreate} />;
37
- };
38
-
39
- const meta: Meta = {
40
- title: 'plugins/plugin-debug/ObjectCreator',
41
- component: ObjectCreator,
42
- render: render(DefaultStory),
43
- decorators: [withClientProvider({ createSpace: true }), withLayout({ tooltips: true }), withTheme],
44
- parameters: {
45
- layout: 'fullscreen',
46
- },
47
- };
48
-
49
- export default meta;
50
-
51
- export const Default = {};
@@ -1,100 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import React, { useMemo, useState } from 'react';
6
-
7
- import { type MutationsProviderParams, TestSchemaType, createSpaceObjectGenerator } from '@dxos/echo-generator';
8
- import { type ReactiveEchoObject, type ReactiveObject, type Space } from '@dxos/react-client/echo';
9
- import { IconButton, Toolbar } from '@dxos/react-ui';
10
- import { createColumnBuilder, type TableColumnDef, Table } from '@dxos/react-ui-table/deprecated';
11
-
12
- const BATCH_SIZE = 10;
13
-
14
- export type CreateObjectsParams = {
15
- schema: string;
16
- enabled: boolean;
17
- objects: number;
18
- mutations: Pick<MutationsProviderParams, 'count' | 'mutationSize' | 'maxContentLength'>;
19
- };
20
-
21
- export type ObjectCreatorProps = {
22
- space: Space;
23
- onAddObjects?: (objects: ReactiveObject<any>[]) => void;
24
- };
25
-
26
- export const ObjectCreator = ({ space, onAddObjects }: ObjectCreatorProps) => {
27
- const generator = useMemo(() => createSpaceObjectGenerator(space), [space]);
28
-
29
- const [objects, setObjects] = useState<CreateObjectsParams[]>(
30
- Object.values(TestSchemaType).map((schema) => ({
31
- schema,
32
- enabled: true,
33
- objects: 10,
34
- mutations: {
35
- count: 10,
36
- mutationSize: 10,
37
- maxContentLength: 1000,
38
- },
39
- })),
40
- );
41
-
42
- const handleCreate = async () => {
43
- for (const params of objects) {
44
- if (!params.enabled) {
45
- continue;
46
- }
47
-
48
- let objectsCreated = 0;
49
- while (objectsCreated < params.objects) {
50
- const objects = (await generator.createObjects({
51
- [params.schema]: Math.min(BATCH_SIZE, params.objects - objectsCreated),
52
- })) as ReactiveEchoObject<any>[];
53
-
54
- await generator.mutateObjects(objects, params.mutations);
55
- objectsCreated += objects.length;
56
- onAddObjects?.(objects);
57
- }
58
- }
59
-
60
- await space.db.flush();
61
- };
62
-
63
- const handleUpdate = (row: CreateObjectsParams, key: string, value: any) => {
64
- const newObjects = [...objects];
65
- Object.assign(newObjects.find((object) => object.schema === row.schema)!, { [key]: value });
66
- setObjects(newObjects);
67
- };
68
-
69
- const { helper, builder } = createColumnBuilder<CreateObjectsParams>();
70
- const columns: TableColumnDef<CreateObjectsParams>[] = [
71
- helper.accessor('enabled', builder.switch({ label: 'Live', onUpdate: handleUpdate })),
72
- helper.accessor('schema', builder.string({ label: 'Schema', classNames: 'font-mono' })),
73
- helper.accessor('objects', builder.number({ label: 'Objects', onUpdate: handleUpdate })),
74
- helper.accessor((obj) => obj.mutations.count, {
75
- id: 'mutations',
76
- ...builder.number({ label: 'Mutations', onUpdate: handleUpdate }),
77
- }),
78
- helper.accessor((obj) => obj.mutations.mutationSize, {
79
- id: 'mutationSize',
80
- ...builder.number({ label: 'Mut. Size', onUpdate: handleUpdate }),
81
- }),
82
- helper.accessor((obj) => obj.mutations.maxContentLength, {
83
- id: 'mutationMaxContentLength',
84
- ...builder.number({ label: 'Length', onUpdate: handleUpdate }),
85
- }),
86
- ];
87
-
88
- return (
89
- <>
90
- <Table.Root>
91
- <Table.Viewport>
92
- <Table.Main<CreateObjectsParams> columns={columns} data={objects} />
93
- </Table.Viewport>
94
- </Table.Root>
95
- <Toolbar.Root classNames='p-1'>
96
- <IconButton icon='ph--plus--regular' label='Create' onClick={handleCreate} />
97
- </Toolbar.Root>
98
- </>
99
- );
100
- };
@@ -1,7 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { DebugSpace } from './DebugSpace';
6
-
7
- export default DebugSpace;