@dxos/plugin-debug 0.8.3 → 0.8.4-main.1068cf700f
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/DebugGraph-6VMEOKEV.mjs +15 -0
- package/dist/lib/browser/DebugGraph-6VMEOKEV.mjs.map +7 -0
- package/dist/lib/browser/DevtoolsOverviewContainer-2C6XMJ3L.mjs +19 -0
- package/dist/lib/browser/DevtoolsOverviewContainer-2C6XMJ3L.mjs.map +7 -0
- package/dist/lib/browser/SpaceGenerator-W3LJORYT.mjs +1152 -0
- package/dist/lib/browser/SpaceGenerator-W3LJORYT.mjs.map +7 -0
- package/dist/lib/browser/app-graph-builder-DEBTVBQG.mjs +599 -0
- package/dist/lib/browser/app-graph-builder-DEBTVBQG.mjs.map +7 -0
- package/dist/lib/browser/{chunk-KS3YBEL7.mjs → chunk-4UFQXPP7.mjs} +13 -3
- package/dist/lib/browser/chunk-4UFQXPP7.mjs.map +7 -0
- package/dist/lib/browser/chunk-A5H5GRV6.mjs +20 -0
- package/dist/lib/browser/chunk-A5H5GRV6.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +42 -46
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/react-context-I3USIAF6.mjs +17 -0
- package/dist/lib/browser/react-context-I3USIAF6.mjs.map +7 -0
- package/dist/lib/browser/react-surface-FMVC5GPV.mjs +758 -0
- package/dist/lib/browser/react-surface-FMVC5GPV.mjs.map +7 -0
- package/dist/lib/browser/settings-SLTQJJNF.mjs +32 -0
- package/dist/lib/browser/settings-SLTQJJNF.mjs.map +7 -0
- package/dist/types/src/DebugPlugin.d.ts +2 -1
- package/dist/types/src/DebugPlugin.d.ts.map +1 -1
- package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts +6 -0
- package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts.map +1 -0
- package/dist/types/src/capabilities/app-graph-builder/index.d.ts +3 -0
- package/dist/types/src/capabilities/app-graph-builder/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/index.d.ts +4 -8
- package/dist/types/src/capabilities/index.d.ts.map +1 -1
- package/dist/types/src/capabilities/react-context/index.d.ts +7 -0
- package/dist/types/src/capabilities/react-context/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-context/react-context.d.ts +10 -0
- package/dist/types/src/capabilities/react-context/react-context.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
- package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
- package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
- package/dist/types/src/capabilities/settings/index.d.ts +3 -0
- package/dist/types/src/capabilities/settings/index.d.ts.map +1 -0
- package/dist/types/src/capabilities/settings/settings.d.ts +6 -0
- package/dist/types/src/capabilities/settings/settings.d.ts.map +1 -0
- package/dist/types/src/components/DebugGraph.d.ts +9 -0
- package/dist/types/src/components/DebugGraph.d.ts.map +1 -0
- package/dist/types/src/components/DebugObjectPanel.d.ts +1 -1
- package/dist/types/src/components/DebugObjectPanel.d.ts.map +1 -1
- package/dist/types/src/components/DebugSettings.d.ts +4 -2
- package/dist/types/src/components/DebugSettings.d.ts.map +1 -1
- package/dist/types/src/components/SpaceGenerator/ObjectGenerator.d.ts +6 -4
- package/dist/types/src/components/SpaceGenerator/ObjectGenerator.d.ts.map +1 -1
- package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts +1 -1
- package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts.map +1 -1
- package/dist/types/src/components/SpaceGenerator/SpaceGenerator.stories.d.ts +13 -4
- package/dist/types/src/components/SpaceGenerator/SpaceGenerator.stories.d.ts.map +1 -1
- package/dist/types/src/components/SpaceGenerator/draw-util.d.ts.map +1 -1
- package/dist/types/src/components/SpaceGenerator/presets.d.ts +5 -8
- package/dist/types/src/components/SpaceGenerator/presets.d.ts.map +1 -1
- package/dist/types/src/components/Wireframe.d.ts +2 -2
- package/dist/types/src/components/Wireframe.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +4 -3
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/meta.d.ts +2 -3
- package/dist/types/src/meta.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +62 -60
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types.d.ts +6 -1
- package/dist/types/src/types.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +79 -71
- package/src/DebugPlugin.tsx +19 -34
- package/src/capabilities/app-graph-builder/app-graph-builder.ts +421 -0
- package/src/capabilities/app-graph-builder/index.ts +7 -0
- package/src/capabilities/index.ts +4 -6
- package/src/capabilities/react-context/index.ts +7 -0
- package/src/capabilities/react-context/react-context.tsx +20 -0
- package/src/capabilities/react-surface/index.ts +7 -0
- package/src/capabilities/react-surface/react-surface.tsx +411 -0
- package/src/capabilities/settings/index.ts +7 -0
- package/src/capabilities/settings/settings.ts +31 -0
- package/src/components/DebugGraph.tsx +15 -0
- package/src/components/DebugObjectPanel.tsx +6 -9
- package/src/components/DebugSettings.tsx +109 -75
- package/src/components/DebugStatus.tsx +2 -2
- package/src/components/DevtoolsOverviewContainer.tsx +2 -2
- package/src/components/SpaceGenerator/ObjectGenerator.tsx +40 -41
- package/src/components/SpaceGenerator/SchemaTable.tsx +2 -2
- package/src/components/SpaceGenerator/SpaceGenerator.stories.tsx +17 -15
- package/src/components/SpaceGenerator/SpaceGenerator.tsx +41 -94
- package/src/components/SpaceGenerator/draw-util.ts +5 -5
- package/src/components/SpaceGenerator/presets.ts +537 -259
- package/src/components/Wireframe.tsx +6 -6
- package/src/components/index.ts +4 -1
- package/src/meta.ts +8 -7
- package/src/translations.ts +9 -5
- package/src/types.ts +9 -1
- package/dist/lib/browser/DebugApp-WSEJPCKY.mjs +0 -225
- package/dist/lib/browser/DebugApp-WSEJPCKY.mjs.map +0 -7
- package/dist/lib/browser/DevtoolsOverviewContainer-IIIWO77Q.mjs +0 -25
- package/dist/lib/browser/DevtoolsOverviewContainer-IIIWO77Q.mjs.map +0 -7
- package/dist/lib/browser/SpaceGenerator-VB6IB2LL.mjs +0 -1238
- package/dist/lib/browser/SpaceGenerator-VB6IB2LL.mjs.map +0 -7
- package/dist/lib/browser/app-graph-builder-6HHJMKVU.mjs +0 -597
- package/dist/lib/browser/app-graph-builder-6HHJMKVU.mjs.map +0 -7
- package/dist/lib/browser/chunk-47JOZTT2.mjs +0 -18
- package/dist/lib/browser/chunk-47JOZTT2.mjs.map +0 -7
- package/dist/lib/browser/chunk-KS3YBEL7.mjs.map +0 -7
- package/dist/lib/browser/react-context-ZQRD2WG2.mjs +0 -16
- package/dist/lib/browser/react-context-ZQRD2WG2.mjs.map +0 -7
- package/dist/lib/browser/react-surface-UI6OK73H.mjs +0 -768
- package/dist/lib/browser/react-surface-UI6OK73H.mjs.map +0 -7
- package/dist/lib/browser/settings-SXQWSIM4.mjs +0 -22
- package/dist/lib/browser/settings-SXQWSIM4.mjs.map +0 -7
- package/dist/types/src/capabilities/app-graph-builder.d.ts +0 -4
- package/dist/types/src/capabilities/app-graph-builder.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-context.d.ts +0 -8
- package/dist/types/src/capabilities/react-context.d.ts.map +0 -1
- package/dist/types/src/capabilities/react-surface.d.ts +0 -4
- package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
- package/dist/types/src/capabilities/settings.d.ts +0 -4
- package/dist/types/src/capabilities/settings.d.ts.map +0 -1
- package/dist/types/src/components/DebugApp/DebugApp.d.ts +0 -6
- package/dist/types/src/components/DebugApp/DebugApp.d.ts.map +0 -1
- package/dist/types/src/components/DebugApp/Tree.d.ts +0 -18
- package/dist/types/src/components/DebugApp/Tree.d.ts.map +0 -1
- package/dist/types/src/components/DebugApp/index.d.ts +0 -3
- package/dist/types/src/components/DebugApp/index.d.ts.map +0 -1
- package/src/capabilities/app-graph-builder.ts +0 -457
- package/src/capabilities/react-context.tsx +0 -16
- package/src/capabilities/react-surface.tsx +0 -397
- package/src/capabilities/settings.ts +0 -19
- package/src/components/DebugApp/DebugApp.tsx +0 -77
- package/src/components/DebugApp/Tree.tsx +0 -103
- package/src/components/DebugApp/index.ts +0 -7
|
@@ -4,15 +4,16 @@
|
|
|
4
4
|
|
|
5
5
|
import React, { useEffect, useState } from 'react';
|
|
6
6
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { useCapabilities } from '@dxos/app-framework/ui';
|
|
8
|
+
import { AppCapabilities } from '@dxos/app-toolkit';
|
|
9
|
+
import { type ConfigProto, SaveConfig, Storage, defs } from '@dxos/config';
|
|
9
10
|
import { log } from '@dxos/log';
|
|
10
11
|
import { useClient } from '@dxos/react-client';
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
12
|
+
import { Icon, IconButton, Input, Select, Toast, useFileDownload, useTranslation } from '@dxos/react-ui';
|
|
13
|
+
import { Settings } from '@dxos/react-ui-form';
|
|
13
14
|
import { setDeep } from '@dxos/util';
|
|
14
15
|
|
|
15
|
-
import {
|
|
16
|
+
import { meta } from '../meta';
|
|
16
17
|
import { type DebugSettingsProps } from '../types';
|
|
17
18
|
|
|
18
19
|
type Toast = {
|
|
@@ -25,14 +26,19 @@ const StorageAdapters = {
|
|
|
25
26
|
idb: defs.Runtime.Client.Storage.StorageDriver.IDB,
|
|
26
27
|
} as const;
|
|
27
28
|
|
|
28
|
-
export
|
|
29
|
-
|
|
29
|
+
export type DebugSettingsComponentProps = {
|
|
30
|
+
settings: DebugSettingsProps;
|
|
31
|
+
onSettingsChange: (fn: (current: DebugSettingsProps) => DebugSettingsProps) => void;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
export const DebugSettings = ({ settings, onSettingsChange }: DebugSettingsComponentProps) => {
|
|
35
|
+
const { t } = useTranslation(meta.id);
|
|
30
36
|
const [toast, setToast] = useState<Toast>();
|
|
31
37
|
const client = useClient();
|
|
32
38
|
const download = useFileDownload();
|
|
33
39
|
// TODO(mykola): Get updates from other places that change Config.
|
|
34
40
|
const [storageConfig, setStorageConfig] = useState<ConfigProto>({});
|
|
35
|
-
const [upload] = useCapabilities(
|
|
41
|
+
const [upload] = useCapabilities(AppCapabilities.FileUploader);
|
|
36
42
|
|
|
37
43
|
useEffect(() => {
|
|
38
44
|
void Storage().then((config) => setStorageConfig(config));
|
|
@@ -46,22 +52,30 @@ export const DebugSettings = ({ settings }: { settings: DebugSettingsProps }) =>
|
|
|
46
52
|
|
|
47
53
|
const handleDownload = async () => {
|
|
48
54
|
const data = await client.diagnostics();
|
|
49
|
-
const file = new Blob([JSON.stringify(data, undefined, 2)], {
|
|
55
|
+
const file = new Blob([JSON.stringify(data, undefined, 2)], {
|
|
56
|
+
type: 'text/plain',
|
|
57
|
+
});
|
|
50
58
|
const fileName = `composer-${new Date().toISOString().replace(/\W/g, '-')}.json`;
|
|
51
59
|
download(file, fileName);
|
|
52
60
|
|
|
53
61
|
if (upload) {
|
|
54
|
-
const info = await upload(new File([file], fileName)
|
|
62
|
+
const info = await upload(client.spaces.default.db, new File([file], fileName));
|
|
55
63
|
if (!info) {
|
|
56
64
|
log.error('diagnostics failed to upload to IPFS');
|
|
57
65
|
return;
|
|
58
66
|
}
|
|
59
|
-
handleToast({
|
|
67
|
+
handleToast({
|
|
68
|
+
title: t('settings uploaded'),
|
|
69
|
+
description: t('settings uploaded to clipboard'),
|
|
70
|
+
});
|
|
60
71
|
|
|
61
72
|
// TODO(nf): move to IpfsPlugin?
|
|
62
73
|
const url = client.config.values.runtime!.services!.ipfs!.gateway + '/' + info.cid;
|
|
63
74
|
void navigator.clipboard.writeText(url);
|
|
64
|
-
handleToast({
|
|
75
|
+
handleToast({
|
|
76
|
+
title: t('settings uploaded'),
|
|
77
|
+
description: t('settings uploaded to clipboard'),
|
|
78
|
+
});
|
|
65
79
|
log.info('diagnostics', { url });
|
|
66
80
|
}
|
|
67
81
|
};
|
|
@@ -70,74 +84,94 @@ export const DebugSettings = ({ settings }: { settings: DebugSettingsProps }) =>
|
|
|
70
84
|
try {
|
|
71
85
|
const info = await client.repair();
|
|
72
86
|
setStorageConfig(await Storage());
|
|
73
|
-
handleToast({
|
|
87
|
+
handleToast({
|
|
88
|
+
title: t('settings repair success'),
|
|
89
|
+
description: JSON.stringify(info, undefined, 2),
|
|
90
|
+
});
|
|
74
91
|
} catch (err: any) {
|
|
75
|
-
handleToast({
|
|
92
|
+
handleToast({
|
|
93
|
+
title: t('settings repair failed'),
|
|
94
|
+
description: err.message,
|
|
95
|
+
});
|
|
76
96
|
}
|
|
77
97
|
};
|
|
78
98
|
|
|
79
99
|
return (
|
|
80
|
-
<
|
|
81
|
-
<
|
|
82
|
-
<
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
</
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
100
|
+
<Settings.Root>
|
|
101
|
+
<Settings.Section title={t('settings title', { ns: meta.id })}>
|
|
102
|
+
<Settings.Group>
|
|
103
|
+
<Settings.ItemInput title={t('settings wireframe')}>
|
|
104
|
+
<Input.Switch
|
|
105
|
+
checked={settings.wireframe}
|
|
106
|
+
onCheckedChange={(checked) => onSettingsChange((s) => ({ ...s, wireframe: !!checked }))}
|
|
107
|
+
/>
|
|
108
|
+
</Settings.ItemInput>
|
|
109
|
+
<Settings.ItemInput title={t('settings download diagnostics')}>
|
|
110
|
+
<IconButton
|
|
111
|
+
icon='ph--download-simple--regular'
|
|
112
|
+
iconOnly
|
|
113
|
+
label={t('settings download diagnostics')}
|
|
114
|
+
onClick={handleDownload}
|
|
115
|
+
/>
|
|
116
|
+
</Settings.ItemInput>
|
|
117
|
+
<Settings.ItemInput title={t('settings repair')}>
|
|
118
|
+
<IconButton
|
|
119
|
+
icon='ph--first-aid-kit--regular'
|
|
120
|
+
iconOnly
|
|
121
|
+
label={t('settings repair')}
|
|
122
|
+
onClick={handleRepair}
|
|
123
|
+
/>
|
|
124
|
+
</Settings.ItemInput>
|
|
125
|
+
|
|
126
|
+
{/* TODO(burdon): Move to layout? */}
|
|
127
|
+
{toast && (
|
|
128
|
+
<Toast.Root>
|
|
129
|
+
<Toast.Body>
|
|
130
|
+
<Toast.Title>
|
|
131
|
+
<Icon icon='ph--gift--duotone' size={5} classNames='inline mr-1' />
|
|
132
|
+
<span>{toast.title}</span>
|
|
133
|
+
</Toast.Title>
|
|
134
|
+
{toast.description && <Toast.Description>{toast.description}</Toast.Description>}
|
|
135
|
+
</Toast.Body>
|
|
136
|
+
</Toast.Root>
|
|
137
|
+
)}
|
|
138
|
+
|
|
139
|
+
<Settings.ItemInput title={t('settings choose storage adaptor')}>
|
|
140
|
+
<Select.Root
|
|
141
|
+
value={
|
|
142
|
+
Object.entries(StorageAdapters).find(
|
|
143
|
+
([_name, value]) => value === storageConfig?.runtime?.client?.storage?.dataStore,
|
|
144
|
+
)?.[0]
|
|
145
|
+
}
|
|
146
|
+
onValueChange={(value) => {
|
|
147
|
+
if (confirm(t('settings storage adapter changed alert'))) {
|
|
148
|
+
updateConfig(
|
|
149
|
+
storageConfig,
|
|
150
|
+
setStorageConfig,
|
|
151
|
+
['runtime', 'client', 'storage', 'dataStore'],
|
|
152
|
+
StorageAdapters[value as keyof typeof StorageAdapters],
|
|
153
|
+
);
|
|
154
|
+
}
|
|
155
|
+
}}
|
|
156
|
+
>
|
|
157
|
+
<Select.TriggerButton placeholder={t('settings data store label')} />
|
|
158
|
+
<Select.Portal>
|
|
159
|
+
<Select.Content>
|
|
160
|
+
<Select.Viewport>
|
|
161
|
+
{Object.keys(StorageAdapters).map((key) => (
|
|
162
|
+
<Select.Option key={key} value={key}>
|
|
163
|
+
{t(`settings storage adaptor ${key} label`)}
|
|
164
|
+
</Select.Option>
|
|
165
|
+
))}
|
|
166
|
+
</Select.Viewport>
|
|
167
|
+
<Select.Arrow />
|
|
168
|
+
</Select.Content>
|
|
169
|
+
</Select.Portal>
|
|
170
|
+
</Select.Root>
|
|
171
|
+
</Settings.ItemInput>
|
|
172
|
+
</Settings.Group>
|
|
173
|
+
</Settings.Section>
|
|
174
|
+
</Settings.Root>
|
|
141
175
|
);
|
|
142
176
|
};
|
|
143
177
|
|
|
@@ -59,7 +59,7 @@ const _timer = (cb: (err?: Error) => void, options?: { min?: number; max?: numbe
|
|
|
59
59
|
// TODO(burdon): Integrate with Sentry?
|
|
60
60
|
const ErrorIndicator = () => {
|
|
61
61
|
const [, forceUpdate] = useState({});
|
|
62
|
-
const errorRef = useRef<Error>();
|
|
62
|
+
const errorRef = useRef<Error>(null);
|
|
63
63
|
useEffect(() => {
|
|
64
64
|
const errorListener = (event: any) => {
|
|
65
65
|
const error: Error = event.error ?? event.reason;
|
|
@@ -83,7 +83,7 @@ const ErrorIndicator = () => {
|
|
|
83
83
|
}, []);
|
|
84
84
|
|
|
85
85
|
const handleReset = () => {
|
|
86
|
-
errorRef.current =
|
|
86
|
+
errorRef.current = null;
|
|
87
87
|
forceUpdate({});
|
|
88
88
|
};
|
|
89
89
|
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import React from 'react';
|
|
6
6
|
|
|
7
|
-
import { Surface } from '@dxos/app-framework';
|
|
7
|
+
import { Surface } from '@dxos/app-framework/ui';
|
|
8
8
|
import { StatsPanel, useStats } from '@dxos/devtools';
|
|
9
9
|
|
|
10
10
|
export const DevtoolsOverviewContainer = () => {
|
|
@@ -12,7 +12,7 @@ export const DevtoolsOverviewContainer = () => {
|
|
|
12
12
|
|
|
13
13
|
return (
|
|
14
14
|
<StatsPanel stats={stats} onRefresh={refreshStats}>
|
|
15
|
-
<Surface role='devtools-overview' />
|
|
15
|
+
<Surface.Surface role='devtools-overview' />
|
|
16
16
|
</StatsPanel>
|
|
17
17
|
);
|
|
18
18
|
};
|
|
@@ -2,58 +2,64 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import type * as Schema from 'effect/Schema';
|
|
6
|
+
|
|
5
7
|
import { addressToA1Notation } from '@dxos/compute';
|
|
6
8
|
import { ComputeGraph, ComputeGraphModel, DEFAULT_OUTPUT, NODE_INPUT, NODE_OUTPUT } from '@dxos/conductor';
|
|
7
|
-
import { DXN, Filter, Key,
|
|
8
|
-
import { type
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
9
|
+
import { DXN, Filter, Key, type Type } from '@dxos/echo';
|
|
10
|
+
import { type OperationInvoker } from '@dxos/operation';
|
|
11
|
+
import { Markdown } from '@dxos/plugin-markdown/types';
|
|
12
|
+
import { Sheet } from '@dxos/plugin-sheet/types';
|
|
13
|
+
import { Diagram } from '@dxos/plugin-sketch/types';
|
|
14
|
+
import { SpaceOperation } from '@dxos/plugin-space/types';
|
|
13
15
|
import { faker } from '@dxos/random';
|
|
16
|
+
import { type Client } from '@dxos/react-client';
|
|
14
17
|
import { type Space } from '@dxos/react-client/echo';
|
|
15
|
-
import {
|
|
16
|
-
import {
|
|
17
|
-
import { createAsyncGenerator, type ValueGenerator } from '@dxos/schema/testing';
|
|
18
|
+
import { View, getTypenameFromQuery } from '@dxos/schema';
|
|
19
|
+
import { type ValueGenerator, createAsyncGenerator } from '@dxos/schema/testing';
|
|
18
20
|
import { range } from '@dxos/util';
|
|
19
21
|
|
|
20
22
|
const generator: ValueGenerator = faker as any;
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
const findViewByTypename = async (views: View.View[], typename: string) => {
|
|
25
|
+
return views.find((view) => getTypenameFromQuery(view.query.ast) === typename);
|
|
26
|
+
};
|
|
23
27
|
|
|
24
|
-
export
|
|
25
|
-
return async (space: Space, n: number, cb?: (objects: T[]) => void): Promise<T[]> => {
|
|
26
|
-
// Find or create mutable schema.
|
|
27
|
-
const schema =
|
|
28
|
-
(await space.db.schemaRegistry.query({ typename: type.typename }).firstOrUndefined()) ??
|
|
29
|
-
(await space.db.schemaRegistry.register([type]))[0];
|
|
28
|
+
export type ObjectGenerator<T> = (space: Space, n: number, cb?: (objects: T[]) => void) => Promise<T[]>;
|
|
30
29
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
export const createGenerator = <S extends Type.Obj.Any>(
|
|
31
|
+
client: Client,
|
|
32
|
+
invokePromise: OperationInvoker.OperationInvoker['invokePromise'],
|
|
33
|
+
schema: S,
|
|
34
|
+
): ObjectGenerator<Schema.Schema.Type<S>> => {
|
|
35
|
+
return async (space: Space, n: number): Promise<Schema.Schema.Type<S>[]> => {
|
|
36
|
+
const typename = schema.typename;
|
|
34
37
|
|
|
35
38
|
// Find or create table and view.
|
|
36
|
-
const
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
const views = await space.db.query(Filter.type(View.View)).run();
|
|
40
|
+
const view = await findViewByTypename(views, typename);
|
|
41
|
+
const staticSchema = client?.graph.schemaRegistry.query({ typename }).runSync()[0];
|
|
42
|
+
if (!view && !staticSchema) {
|
|
43
|
+
await invokePromise(SpaceOperation.AddSchema, { db: space.db, schema, show: false });
|
|
44
|
+
} else if (!view && staticSchema) {
|
|
45
|
+
await invokePromise(SpaceOperation.UseStaticSchema, { db: space.db, typename, show: false });
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
|
|
48
|
+
// Create objects.
|
|
49
|
+
const generate = createAsyncGenerator(generator, schema, { db: space.db });
|
|
50
|
+
return generate.createObjects(n);
|
|
45
51
|
};
|
|
46
52
|
};
|
|
47
53
|
|
|
48
54
|
export const staticGenerators = new Map<string, ObjectGenerator<any>>([
|
|
49
55
|
[
|
|
50
|
-
|
|
56
|
+
Markdown.Document.typename,
|
|
51
57
|
async (space, n, cb) => {
|
|
52
58
|
const objects = range(n).map(() => {
|
|
53
59
|
return space.db.add(
|
|
54
|
-
|
|
60
|
+
Markdown.make({
|
|
55
61
|
name: faker.commerce.productName(),
|
|
56
|
-
content:
|
|
62
|
+
content: faker.lorem.sentences(5),
|
|
57
63
|
}),
|
|
58
64
|
);
|
|
59
65
|
});
|
|
@@ -63,17 +69,10 @@ export const staticGenerators = new Map<string, ObjectGenerator<any>>([
|
|
|
63
69
|
},
|
|
64
70
|
],
|
|
65
71
|
[
|
|
66
|
-
|
|
72
|
+
Diagram.Diagram.typename,
|
|
67
73
|
async (space, n, cb) => {
|
|
68
74
|
const objects = range(n).map(() => {
|
|
69
|
-
|
|
70
|
-
const obj = space.db.add(
|
|
71
|
-
Obj.make(DiagramType, {
|
|
72
|
-
name: faker.commerce.productName(),
|
|
73
|
-
canvas: Ref.make(Obj.make(CanvasType, { content: {} })),
|
|
74
|
-
}),
|
|
75
|
-
);
|
|
76
|
-
|
|
75
|
+
const obj = space.db.add(Diagram.make({ name: faker.commerce.productName() }));
|
|
77
76
|
return obj;
|
|
78
77
|
});
|
|
79
78
|
|
|
@@ -83,10 +82,10 @@ export const staticGenerators = new Map<string, ObjectGenerator<any>>([
|
|
|
83
82
|
],
|
|
84
83
|
// TODO(burdon): Create unit tests.
|
|
85
84
|
[
|
|
86
|
-
|
|
85
|
+
Sheet.Sheet.typename,
|
|
87
86
|
async (space, n, cb) => {
|
|
88
87
|
const objects = range(n).map(() => {
|
|
89
|
-
const cells: Record<string, CellValue> = {};
|
|
88
|
+
const cells: Record<string, Sheet.CellValue> = {};
|
|
90
89
|
const year = new Date().getFullYear();
|
|
91
90
|
const cols = 4;
|
|
92
91
|
const rows = 16;
|
|
@@ -108,7 +107,7 @@ export const staticGenerators = new Map<string, ObjectGenerator<any>>([
|
|
|
108
107
|
// TODO(burdon): Set width.
|
|
109
108
|
// TODO(burdon): Set formatting for columns.
|
|
110
109
|
return space.db.add(
|
|
111
|
-
|
|
110
|
+
Sheet.make({
|
|
112
111
|
name: faker.commerce.productName(),
|
|
113
112
|
cells,
|
|
114
113
|
}),
|
|
@@ -19,8 +19,8 @@ export const SchemaTable = ({ types, objects = {}, label, onClick }: SchemaTable
|
|
|
19
19
|
<h2 className='p-2'>{label}</h2>
|
|
20
20
|
{types.map((type) => (
|
|
21
21
|
<div key={type.typename} className='grid grid-cols-subgrid col-span-3 items-center'>
|
|
22
|
-
<div className='
|
|
23
|
-
<div className='
|
|
22
|
+
<div className='pli-2 text-sm font-mono text-subdued'>{type.typename}</div>
|
|
23
|
+
<div className='pli-2 text-right font-mono'>{objects[type.typename] ?? 0}</div>
|
|
24
24
|
<IconButton
|
|
25
25
|
variant='ghost'
|
|
26
26
|
icon='ph--plus--regular'
|
|
@@ -2,16 +2,16 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import '@
|
|
6
|
-
|
|
7
|
-
import { type Meta } from '@storybook/react';
|
|
5
|
+
import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
6
|
+
import * as Effect from 'effect/Effect';
|
|
8
7
|
import React from 'react';
|
|
9
8
|
|
|
10
|
-
import {
|
|
9
|
+
import { OperationPlugin } from '@dxos/app-framework';
|
|
11
10
|
import { withPluginManager } from '@dxos/app-framework/testing';
|
|
12
11
|
import { ClientPlugin } from '@dxos/plugin-client';
|
|
13
12
|
import { useSpaces } from '@dxos/react-client/echo';
|
|
14
|
-
import {
|
|
13
|
+
import { withTheme } from '@dxos/react-ui/testing';
|
|
14
|
+
import { render } from '@dxos/storybook-utils';
|
|
15
15
|
|
|
16
16
|
import { SpaceGenerator } from './SpaceGenerator';
|
|
17
17
|
|
|
@@ -24,29 +24,31 @@ const DefaultStory = () => {
|
|
|
24
24
|
return <SpaceGenerator space={space} />;
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
-
const meta
|
|
27
|
+
const meta = {
|
|
28
28
|
title: 'plugins/plugin-debug/SpaceGenerator',
|
|
29
|
-
component: SpaceGenerator,
|
|
29
|
+
component: SpaceGenerator as any,
|
|
30
30
|
render: render(DefaultStory),
|
|
31
31
|
decorators: [
|
|
32
|
+
withTheme(),
|
|
32
33
|
withPluginManager({
|
|
33
34
|
plugins: [
|
|
34
35
|
ClientPlugin({
|
|
35
|
-
onClientInitialized:
|
|
36
|
-
|
|
37
|
-
|
|
36
|
+
onClientInitialized: ({ client }) =>
|
|
37
|
+
Effect.gen(function* () {
|
|
38
|
+
yield* Effect.promise(() => client.halo.createIdentity());
|
|
39
|
+
}),
|
|
38
40
|
}),
|
|
39
|
-
|
|
41
|
+
OperationPlugin(),
|
|
40
42
|
],
|
|
41
43
|
}),
|
|
42
|
-
withLayout(),
|
|
43
|
-
withTheme,
|
|
44
44
|
],
|
|
45
45
|
parameters: {
|
|
46
46
|
layout: 'fullscreen',
|
|
47
47
|
},
|
|
48
|
-
}
|
|
48
|
+
} satisfies Meta<typeof DefaultStory>;
|
|
49
49
|
|
|
50
50
|
export default meta;
|
|
51
51
|
|
|
52
|
-
|
|
52
|
+
type Story = StoryObj<typeof meta>;
|
|
53
|
+
|
|
54
|
+
export const Default: Story = {};
|