@dxos/plugin-debug 0.8.4-main.67995b8 → 0.8.4-main.69d29f4

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 (131) hide show
  1. package/dist/lib/browser/DebugGraph-6VMEOKEV.mjs +15 -0
  2. package/dist/lib/browser/DebugGraph-6VMEOKEV.mjs.map +7 -0
  3. package/dist/lib/browser/DevtoolsOverviewContainer-77PKFLYV.mjs +19 -0
  4. package/dist/lib/browser/DevtoolsOverviewContainer-77PKFLYV.mjs.map +7 -0
  5. package/dist/lib/browser/{SpaceGenerator-6ZOCEREN.mjs → SpaceGenerator-H33AEFGC.mjs} +382 -211
  6. package/dist/lib/browser/SpaceGenerator-H33AEFGC.mjs.map +7 -0
  7. package/dist/lib/browser/app-graph-builder-FBDRMMYF.mjs +597 -0
  8. package/dist/lib/browser/app-graph-builder-FBDRMMYF.mjs.map +7 -0
  9. package/dist/lib/browser/{chunk-AJA6RYN3.mjs → chunk-4UFQXPP7.mjs} +12 -2
  10. package/dist/lib/browser/chunk-4UFQXPP7.mjs.map +7 -0
  11. package/dist/lib/browser/chunk-A5H5GRV6.mjs +20 -0
  12. package/dist/lib/browser/chunk-A5H5GRV6.mjs.map +7 -0
  13. package/dist/lib/browser/index.mjs +36 -41
  14. package/dist/lib/browser/index.mjs.map +4 -4
  15. package/dist/lib/browser/meta.json +1 -1
  16. package/dist/lib/browser/react-context-FSWBT3MH.mjs +17 -0
  17. package/dist/lib/browser/react-context-FSWBT3MH.mjs.map +7 -0
  18. package/dist/lib/browser/react-surface-2N6CPSHR.mjs +757 -0
  19. package/dist/lib/browser/react-surface-2N6CPSHR.mjs.map +7 -0
  20. package/dist/lib/browser/settings-KA4GN73K.mjs +31 -0
  21. package/dist/lib/browser/settings-KA4GN73K.mjs.map +7 -0
  22. package/dist/types/src/DebugPlugin.d.ts +2 -1
  23. package/dist/types/src/DebugPlugin.d.ts.map +1 -1
  24. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts +6 -0
  25. package/dist/types/src/capabilities/app-graph-builder/app-graph-builder.d.ts.map +1 -0
  26. package/dist/types/src/capabilities/app-graph-builder/index.d.ts +3 -0
  27. package/dist/types/src/capabilities/app-graph-builder/index.d.ts.map +1 -0
  28. package/dist/types/src/capabilities/index.d.ts +4 -8
  29. package/dist/types/src/capabilities/index.d.ts.map +1 -1
  30. package/dist/types/src/capabilities/react-context/index.d.ts +7 -0
  31. package/dist/types/src/capabilities/react-context/index.d.ts.map +1 -0
  32. package/dist/types/src/capabilities/react-context/react-context.d.ts +10 -0
  33. package/dist/types/src/capabilities/react-context/react-context.d.ts.map +1 -0
  34. package/dist/types/src/capabilities/react-surface/index.d.ts +3 -0
  35. package/dist/types/src/capabilities/react-surface/index.d.ts.map +1 -0
  36. package/dist/types/src/capabilities/react-surface/react-surface.d.ts +5 -0
  37. package/dist/types/src/capabilities/react-surface/react-surface.d.ts.map +1 -0
  38. package/dist/types/src/capabilities/settings/index.d.ts +3 -0
  39. package/dist/types/src/capabilities/settings/index.d.ts.map +1 -0
  40. package/dist/types/src/capabilities/settings/settings.d.ts +5 -0
  41. package/dist/types/src/capabilities/settings/settings.d.ts.map +1 -0
  42. package/dist/types/src/components/DebugGraph.d.ts +9 -0
  43. package/dist/types/src/components/DebugGraph.d.ts.map +1 -0
  44. package/dist/types/src/components/DebugObjectPanel.d.ts +1 -1
  45. package/dist/types/src/components/DebugObjectPanel.d.ts.map +1 -1
  46. package/dist/types/src/components/DebugSettings.d.ts +4 -2
  47. package/dist/types/src/components/DebugSettings.d.ts.map +1 -1
  48. package/dist/types/src/components/SpaceGenerator/ObjectGenerator.d.ts +5 -5
  49. package/dist/types/src/components/SpaceGenerator/ObjectGenerator.d.ts.map +1 -1
  50. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts +2 -2
  51. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts.map +1 -1
  52. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.stories.d.ts +13 -4
  53. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.stories.d.ts.map +1 -1
  54. package/dist/types/src/components/SpaceGenerator/draw-util.d.ts.map +1 -1
  55. package/dist/types/src/components/SpaceGenerator/presets.d.ts +4 -4
  56. package/dist/types/src/components/SpaceGenerator/presets.d.ts.map +1 -1
  57. package/dist/types/src/components/Wireframe.d.ts +2 -2
  58. package/dist/types/src/components/Wireframe.d.ts.map +1 -1
  59. package/dist/types/src/components/index.d.ts +4 -3
  60. package/dist/types/src/components/index.d.ts.map +1 -1
  61. package/dist/types/src/meta.d.ts +2 -3
  62. package/dist/types/src/meta.d.ts.map +1 -1
  63. package/dist/types/src/translations.d.ts +3 -1
  64. package/dist/types/src/translations.d.ts.map +1 -1
  65. package/dist/types/src/types.d.ts +6 -1
  66. package/dist/types/src/types.d.ts.map +1 -1
  67. package/dist/types/tsconfig.tsbuildinfo +1 -1
  68. package/package.json +77 -69
  69. package/src/DebugPlugin.tsx +17 -33
  70. package/src/capabilities/app-graph-builder/app-graph-builder.ts +419 -0
  71. package/src/capabilities/app-graph-builder/index.ts +7 -0
  72. package/src/capabilities/index.ts +4 -6
  73. package/src/capabilities/react-context/index.ts +7 -0
  74. package/src/capabilities/react-context/react-context.tsx +20 -0
  75. package/src/capabilities/react-surface/index.ts +7 -0
  76. package/src/capabilities/react-surface/react-surface.tsx +409 -0
  77. package/src/capabilities/settings/index.ts +7 -0
  78. package/src/capabilities/settings/settings.ts +30 -0
  79. package/src/components/DebugGraph.tsx +15 -0
  80. package/src/components/DebugObjectPanel.tsx +6 -8
  81. package/src/components/DebugSettings.tsx +109 -75
  82. package/src/components/DebugStatus.tsx +2 -2
  83. package/src/components/DevtoolsOverviewContainer.tsx +1 -1
  84. package/src/components/SpaceGenerator/ObjectGenerator.tsx +28 -35
  85. package/src/components/SpaceGenerator/SchemaTable.tsx +2 -2
  86. package/src/components/SpaceGenerator/SpaceGenerator.stories.tsx +17 -15
  87. package/src/components/SpaceGenerator/SpaceGenerator.tsx +24 -19
  88. package/src/components/SpaceGenerator/draw-util.ts +5 -5
  89. package/src/components/SpaceGenerator/presets.ts +324 -42
  90. package/src/components/Wireframe.tsx +6 -6
  91. package/src/components/index.ts +4 -1
  92. package/src/meta.ts +8 -7
  93. package/src/translations.ts +3 -1
  94. package/src/types.ts +9 -1
  95. package/dist/lib/browser/DebugApp-ZDL4CPY5.mjs +0 -228
  96. package/dist/lib/browser/DebugApp-ZDL4CPY5.mjs.map +0 -7
  97. package/dist/lib/browser/DevtoolsOverviewContainer-EPD6EWT5.mjs +0 -25
  98. package/dist/lib/browser/DevtoolsOverviewContainer-EPD6EWT5.mjs.map +0 -7
  99. package/dist/lib/browser/SpaceGenerator-6ZOCEREN.mjs.map +0 -7
  100. package/dist/lib/browser/app-graph-builder-SQXFD2BL.mjs +0 -597
  101. package/dist/lib/browser/app-graph-builder-SQXFD2BL.mjs.map +0 -7
  102. package/dist/lib/browser/chunk-5XPIRNQS.mjs +0 -18
  103. package/dist/lib/browser/chunk-5XPIRNQS.mjs.map +0 -7
  104. package/dist/lib/browser/chunk-AJA6RYN3.mjs.map +0 -7
  105. package/dist/lib/browser/react-context-NVAGLAJD.mjs +0 -16
  106. package/dist/lib/browser/react-context-NVAGLAJD.mjs.map +0 -7
  107. package/dist/lib/browser/react-surface-CHHHE5CF.mjs +0 -768
  108. package/dist/lib/browser/react-surface-CHHHE5CF.mjs.map +0 -7
  109. package/dist/lib/browser/settings-LSSWLM5I.mjs +0 -22
  110. package/dist/lib/browser/settings-LSSWLM5I.mjs.map +0 -7
  111. package/dist/types/src/capabilities/app-graph-builder.d.ts +0 -4
  112. package/dist/types/src/capabilities/app-graph-builder.d.ts.map +0 -1
  113. package/dist/types/src/capabilities/react-context.d.ts +0 -8
  114. package/dist/types/src/capabilities/react-context.d.ts.map +0 -1
  115. package/dist/types/src/capabilities/react-surface.d.ts +0 -4
  116. package/dist/types/src/capabilities/react-surface.d.ts.map +0 -1
  117. package/dist/types/src/capabilities/settings.d.ts +0 -4
  118. package/dist/types/src/capabilities/settings.d.ts.map +0 -1
  119. package/dist/types/src/components/DebugApp/DebugApp.d.ts +0 -6
  120. package/dist/types/src/components/DebugApp/DebugApp.d.ts.map +0 -1
  121. package/dist/types/src/components/DebugApp/Tree.d.ts +0 -18
  122. package/dist/types/src/components/DebugApp/Tree.d.ts.map +0 -1
  123. package/dist/types/src/components/DebugApp/index.d.ts +0 -3
  124. package/dist/types/src/components/DebugApp/index.d.ts.map +0 -1
  125. package/src/capabilities/app-graph-builder.ts +0 -457
  126. package/src/capabilities/react-context.tsx +0 -16
  127. package/src/capabilities/react-surface.tsx +0 -397
  128. package/src/capabilities/settings.ts +0 -19
  129. package/src/components/DebugApp/DebugApp.tsx +0 -84
  130. package/src/components/DebugApp/Tree.tsx +0 -103
  131. 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 { Capabilities, useCapabilities } from '@dxos/app-framework';
8
- import { type ConfigProto, defs, SaveConfig, Storage } from '@dxos/config';
7
+ import { Common } from '@dxos/app-framework';
8
+ import { useCapabilities } from '@dxos/app-framework/react';
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 { useTranslation, Button, Toast, Input, useFileDownload, Select, Icon } from '@dxos/react-ui';
12
- import { DeprecatedFormContainer, DeprecatedFormInput } from '@dxos/react-ui-form';
12
+ import { Icon, IconButton, Input, Select, Toast, useFileDownload, useTranslation } from '@dxos/react-ui';
13
+ import { ControlGroup, ControlItemInput, ControlPage, ControlSection } from '@dxos/react-ui-form';
13
14
  import { setDeep } from '@dxos/util';
14
15
 
15
- import { DEBUG_PLUGIN } from '../meta';
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 const DebugSettings = ({ settings }: { settings: DebugSettingsProps }) => {
29
- const { t } = useTranslation(DEBUG_PLUGIN);
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(Capabilities.FileUploader);
41
+ const [upload] = useCapabilities(Common.Capability.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)], { type: 'text/plain' });
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), client.spaces.default);
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({ title: t('settings uploaded'), description: t('settings uploaded to clipboard') });
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({ title: t('settings uploaded'), description: t('settings uploaded to clipboard') });
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({ title: t('settings repair success'), description: JSON.stringify(info, undefined, 2) });
87
+ handleToast({
88
+ title: t('settings repair success'),
89
+ description: JSON.stringify(info, undefined, 2),
90
+ });
74
91
  } catch (err: any) {
75
- handleToast({ title: t('settings repair failed'), description: err.message });
92
+ handleToast({
93
+ title: t('settings repair failed'),
94
+ description: err.message,
95
+ });
76
96
  }
77
97
  };
78
98
 
79
99
  return (
80
- <DeprecatedFormContainer>
81
- <DeprecatedFormInput label={t('settings wireframe')}>
82
- <Input.Switch checked={settings.wireframe} onCheckedChange={(checked) => (settings.wireframe = !!checked)} />
83
- </DeprecatedFormInput>
84
- <DeprecatedFormInput label={t('settings download diagnostics')}>
85
- <Button onClick={handleDownload}>
86
- <Icon icon='ph--download-simple--regular' size={5} />
87
- </Button>
88
- </DeprecatedFormInput>
89
- <DeprecatedFormInput label={t('settings repair')}>
90
- <Button onClick={handleRepair}>
91
- <Icon icon='ph--first-aid-kit--regular' size={5} />
92
- </Button>
93
- </DeprecatedFormInput>
94
-
95
- {/* TODO(burdon): Move to layout? */}
96
- {toast && (
97
- <Toast.Root>
98
- <Toast.Body>
99
- <Toast.Title>
100
- <Icon icon='ph--gift--duotone' size={5} classNames='inline mr-1' />
101
- <span>{toast.title}</span>
102
- </Toast.Title>
103
- {toast.description && <Toast.Description>{toast.description}</Toast.Description>}
104
- </Toast.Body>
105
- </Toast.Root>
106
- )}
107
-
108
- <DeprecatedFormInput label={t('settings choose storage adaptor')}>
109
- <Select.Root
110
- value={
111
- Object.entries(StorageAdapters).find(
112
- ([name, value]) => value === storageConfig?.runtime?.client?.storage?.dataStore,
113
- )?.[0]
114
- }
115
- onValueChange={(value) => {
116
- if (confirm(t('settings storage adapter changed alert'))) {
117
- updateConfig(
118
- storageConfig,
119
- setStorageConfig,
120
- ['runtime', 'client', 'storage', 'dataStore'],
121
- StorageAdapters[value as keyof typeof StorageAdapters],
122
- );
123
- }
124
- }}
125
- >
126
- <Select.TriggerButton placeholder={t('settings data store label')} />
127
- <Select.Portal>
128
- <Select.Content>
129
- <Select.Viewport>
130
- {Object.keys(StorageAdapters).map((key) => (
131
- <Select.Option key={key} value={key}>
132
- {t(`settings storage adaptor ${key} label`)}
133
- </Select.Option>
134
- ))}
135
- </Select.Viewport>
136
- </Select.Content>
137
- </Select.Portal>
138
- </Select.Root>
139
- </DeprecatedFormInput>
140
- </DeprecatedFormContainer>
100
+ <ControlPage>
101
+ <ControlSection title={t('settings title', { ns: meta.id })}>
102
+ <ControlGroup>
103
+ <ControlItemInput title={t('settings wireframe')}>
104
+ <Input.Switch
105
+ checked={settings.wireframe}
106
+ onCheckedChange={(checked) => onSettingsChange((s) => ({ ...s, wireframe: !!checked }))}
107
+ />
108
+ </ControlItemInput>
109
+ <ControlItemInput 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
+ </ControlItemInput>
117
+ <ControlItemInput 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
+ </ControlItemInput>
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
+ <ControlItemInput 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
+ </ControlItemInput>
172
+ </ControlGroup>
173
+ </ControlSection>
174
+ </ControlPage>
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 = undefined;
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/react';
8
8
  import { StatsPanel, useStats } from '@dxos/devtools';
9
9
 
10
10
  export const DevtoolsOverviewContainer = () => {
@@ -2,47 +2,47 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { createIntent, type PromiseIntentDispatcher } from '@dxos/app-framework';
5
+ import type * as Schema from 'effect/Schema';
6
+
6
7
  import { addressToA1Notation } from '@dxos/compute';
7
8
  import { ComputeGraph, ComputeGraphModel, DEFAULT_OUTPUT, NODE_INPUT, NODE_OUTPUT } from '@dxos/conductor';
8
- import { DXN, Filter, Key, Obj, Ref, Type } from '@dxos/echo';
9
- import { type TypedObject } from '@dxos/echo-schema';
9
+ import { DXN, Filter, Key, type Type } from '@dxos/echo';
10
+ import { type OperationInvoker } from '@dxos/operation';
10
11
  import { Markdown } from '@dxos/plugin-markdown/types';
11
- import { createSheet } from '@dxos/plugin-sheet/types';
12
- import { SheetType, type CellValue } from '@dxos/plugin-sheet/types';
13
- import { CanvasType, DiagramType } from '@dxos/plugin-sketch/types';
14
- import { SpaceAction } from '@dxos/plugin-space/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';
15
15
  import { faker } from '@dxos/random';
16
16
  import { type Client } from '@dxos/react-client';
17
17
  import { type Space } from '@dxos/react-client/echo';
18
- import { DataType } from '@dxos/schema';
19
- import { createAsyncGenerator, type ValueGenerator } from '@dxos/schema/testing';
18
+ import { View, getTypenameFromQuery } from '@dxos/schema';
19
+ import { type ValueGenerator, createAsyncGenerator } from '@dxos/schema/testing';
20
20
  import { range } from '@dxos/util';
21
21
 
22
22
  const generator: ValueGenerator = faker as any;
23
23
 
24
- export type ObjectGenerator<T extends Obj.Any> = (space: Space, n: number, cb?: (objects: T[]) => void) => Promise<T[]>;
25
-
26
- const findViewByTypename = async (views: DataType.View[], typename: string) => {
27
- return views.find((view) => view.query.typename === typename);
24
+ const findViewByTypename = async (views: View.View[], typename: string) => {
25
+ return views.find((view) => getTypenameFromQuery(view.query.ast) === typename);
28
26
  };
29
27
 
30
- export const createGenerator = <T extends Obj.Any>(
28
+ export type ObjectGenerator<T> = (space: Space, n: number, cb?: (objects: T[]) => void) => Promise<T[]>;
29
+
30
+ export const createGenerator = <S extends Type.Obj.Any>(
31
31
  client: Client,
32
- dispatch: PromiseIntentDispatcher,
33
- schema: TypedObject<T>,
34
- ): ObjectGenerator<T> => {
35
- return async (space: Space, n: number, cb?: (objects: T[]) => void): Promise<T[]> => {
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
36
  const typename = schema.typename;
37
37
 
38
38
  // Find or create table and view.
39
- const { objects: views } = await space.db.query(Filter.type(DataType.View)).run();
39
+ const views = await space.db.query(Filter.type(View.View)).run();
40
40
  const view = await findViewByTypename(views, typename);
41
- const staticSchema = client?.graph.schemaRegistry.schemas.find((schema) => Type.getTypename(schema) === typename);
41
+ const staticSchema = client?.graph.schemaRegistry.query({ typename }).runSync()[0];
42
42
  if (!view && !staticSchema) {
43
- await dispatch(createIntent(SpaceAction.AddSchema, { space, schema }));
43
+ await invokePromise(SpaceOperation.AddSchema, { db: space.db, schema, show: false });
44
44
  } else if (!view && staticSchema) {
45
- await dispatch(createIntent(SpaceAction.UseStaticSchema, { space, typename }));
45
+ await invokePromise(SpaceOperation.UseStaticSchema, { db: space.db, typename, show: false });
46
46
  }
47
47
 
48
48
  // Create objects.
@@ -57,7 +57,7 @@ export const staticGenerators = new Map<string, ObjectGenerator<any>>([
57
57
  async (space, n, cb) => {
58
58
  const objects = range(n).map(() => {
59
59
  return space.db.add(
60
- Markdown.makeDocument({
60
+ Markdown.make({
61
61
  name: faker.commerce.productName(),
62
62
  content: faker.lorem.sentences(5),
63
63
  }),
@@ -69,17 +69,10 @@ export const staticGenerators = new Map<string, ObjectGenerator<any>>([
69
69
  },
70
70
  ],
71
71
  [
72
- DiagramType.typename,
72
+ Diagram.Diagram.typename,
73
73
  async (space, n, cb) => {
74
74
  const objects = range(n).map(() => {
75
- // TODO(burdon): Generate diagram.
76
- const obj = space.db.add(
77
- Obj.make(DiagramType, {
78
- name: faker.commerce.productName(),
79
- canvas: Ref.make(Obj.make(CanvasType, { content: {} })),
80
- }),
81
- );
82
-
75
+ const obj = space.db.add(Diagram.make({ name: faker.commerce.productName() }));
83
76
  return obj;
84
77
  });
85
78
 
@@ -89,10 +82,10 @@ export const staticGenerators = new Map<string, ObjectGenerator<any>>([
89
82
  ],
90
83
  // TODO(burdon): Create unit tests.
91
84
  [
92
- SheetType.typename,
85
+ Sheet.Sheet.typename,
93
86
  async (space, n, cb) => {
94
87
  const objects = range(n).map(() => {
95
- const cells: Record<string, CellValue> = {};
88
+ const cells: Record<string, Sheet.CellValue> = {};
96
89
  const year = new Date().getFullYear();
97
90
  const cols = 4;
98
91
  const rows = 16;
@@ -114,7 +107,7 @@ export const staticGenerators = new Map<string, ObjectGenerator<any>>([
114
107
  // TODO(burdon): Set width.
115
108
  // TODO(burdon): Set formatting for columns.
116
109
  return space.db.add(
117
- createSheet({
110
+ Sheet.make({
118
111
  name: faker.commerce.productName(),
119
112
  cells,
120
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='px-2 text-sm font-mono text-subdued'>{type.typename}</div>
23
- <div className='px-2 text-right font-mono'>{objects[type.typename] ?? 0}</div>
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 '@dxos-theme';
6
-
7
- import { type Meta } from '@storybook/react-vite';
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 { IntentPlugin } from '@dxos/app-framework';
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 { render, withLayout, withTheme } from '@dxos/storybook-utils';
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: 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: async (_, client) => {
36
- await client.halo.createIdentity();
37
- },
36
+ onClientInitialized: ({ client }) =>
37
+ Effect.gen(function* () {
38
+ yield* Effect.promise(() => client.halo.createIdentity());
39
+ }),
38
40
  }),
39
- IntentPlugin(),
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
- export const Default = {};
52
+ type Story = StoryObj<typeof meta>;
53
+
54
+ export const Default: Story = {};
@@ -4,62 +4,67 @@
4
4
 
5
5
  import React, { useCallback, useMemo, useState } from 'react';
6
6
 
7
- import { useIntentDispatcher } from '@dxos/app-framework';
7
+ import { useOperationInvoker } from '@dxos/app-framework/react';
8
8
  import { ComputeGraph } from '@dxos/conductor';
9
- import { Filter, type Obj } from '@dxos/echo';
9
+ import { Filter, Obj, type Type } from '@dxos/echo';
10
10
  import { Markdown } from '@dxos/plugin-markdown/types';
11
- import { SheetType } from '@dxos/plugin-sheet/types';
12
- import { DiagramType } from '@dxos/plugin-sketch/types';
11
+ import { Sheet } from '@dxos/plugin-sheet/types';
12
+ import { Diagram } from '@dxos/plugin-sketch/types';
13
13
  import { useClient } from '@dxos/react-client';
14
- import { getTypename, type Space } from '@dxos/react-client/echo';
14
+ import { type Space } from '@dxos/react-client/echo';
15
15
  import { IconButton, Input, Toolbar, useAsyncEffect } from '@dxos/react-ui';
16
16
  import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
17
- import { DataType } from '@dxos/schema';
17
+ import { Organization, Person, Task } from '@dxos/types';
18
18
  import { jsonKeyReplacer, sortKeys } from '@dxos/util';
19
19
 
20
- import { createGenerator, staticGenerators, type ObjectGenerator } from './ObjectGenerator';
21
- import { SchemaTable } from './SchemaTable';
20
+ import { type ObjectGenerator, createGenerator, staticGenerators } from './ObjectGenerator';
22
21
  import { generator } from './presets';
22
+ import { SchemaTable } from './SchemaTable';
23
23
 
24
24
  export type SpaceGeneratorProps = {
25
25
  space: Space;
26
- onCreateObjects?: (objects: Obj.Any[]) => void;
26
+ onCreateObjects?: (objects: Obj.Unknown[]) => void;
27
27
  };
28
28
 
29
29
  export const SpaceGenerator = ({ space, onCreateObjects }: SpaceGeneratorProps) => {
30
- const { dispatchPromise: dispatch } = useIntentDispatcher();
30
+ const { invokePromise } = useOperationInvoker();
31
31
  const client = useClient();
32
- const staticTypes = [Markdown.Document, DiagramType, SheetType, ComputeGraph]; // TODO(burdon): Make extensible.
33
- const recordTypes = [DataType.Organization, DataType.Project, DataType.Person, DataType.Message];
32
+ const staticTypes = [Markdown.Document, Diagram.Diagram, Sheet.Sheet, ComputeGraph]; // TODO(burdon): Make extensible.
33
+ const recordTypes: Type.Obj.Any[] = [Organization.Organization, Person.Person, Task.Task];
34
34
  const [count, setCount] = useState(1);
35
35
  const [info, setInfo] = useState<any>({});
36
36
  const presets = useMemo(() => generator(), []);
37
37
 
38
+ // Register types.
39
+ useAsyncEffect(async () => {
40
+ await client.addTypes([...staticTypes, ...recordTypes, ...presets.schemas]);
41
+ }, [client]);
42
+
38
43
  // Create type generators.
39
44
  const typeMap = useMemo(() => {
40
- client.addTypes([...staticTypes, ...recordTypes, ...presets.schemas]);
41
45
  const recordGenerators = new Map<string, ObjectGenerator<any>>(
42
- recordTypes.map((type) => [type.typename, createGenerator(client, dispatch, type as any)]),
46
+ recordTypes.map((type) => [type.typename, createGenerator(client, invokePromise, type)]),
43
47
  );
44
48
 
45
49
  return new Map([...staticGenerators, ...presets.items, ...recordGenerators]);
46
- }, [client, recordTypes]);
50
+ }, [client, recordTypes, invokePromise]);
47
51
 
48
52
  // Query space to get info.
49
53
  const updateInfo = async () => {
50
54
  // Create schema map.
51
55
  const echoSchema = await space.db.schemaRegistry.query().run();
52
- const staticSchema = space.db.graph.schemaRegistry.schemas;
56
+ const staticSchema = await space.db.graph.schemaRegistry.query().run();
53
57
 
54
58
  // Create object map.
55
- const { objects } = await space.db.query(Filter.everything()).run();
59
+ const objects = await space.db.query(Filter.everything()).run();
56
60
  const objectMap = sortKeys(
57
61
  objects.reduce<Record<string, number>>((map, obj) => {
58
- const type = getTypename(obj);
62
+ const type = Obj.getTypename(obj);
59
63
  if (type) {
60
64
  const count = map[type] ?? 0;
61
65
  map[type] = count + 1;
62
66
  }
67
+
63
68
  return map;
64
69
  }, {}),
65
70
  );
@@ -112,7 +117,7 @@ export const SpaceGenerator = ({ space, onCreateObjects }: SpaceGeneratorProps)
112
117
  <SchemaTable types={presets.types} objects={info.objects} label='Presets' onClick={handleCreateData} />
113
118
 
114
119
  <div>
115
- <SyntaxHighlighter classNames='flex text-xs' language='json'>
120
+ <SyntaxHighlighter language='json' classNames='text-xs'>
116
121
  {JSON.stringify({ space, ...info }, jsonKeyReplacer({ truncate: true }), 2)}
117
122
  </SyntaxHighlighter>
118
123
  </div>
@@ -3,20 +3,20 @@
3
3
  //
4
4
 
5
5
  // TODO(burdon): workerize-loader dep.
6
- import { Graph, type Edge, type PlainObject } from '@antv/graphlib';
6
+ import { type Edge, Graph, type PlainObject } from '@antv/graphlib';
7
7
  import {
8
- type Layout,
9
8
  D3ForceLayout,
10
9
  type D3ForceLayoutOptions,
11
10
  GridLayout,
12
11
  type GridLayoutOptions,
12
+ type Layout,
13
13
  RadialLayout,
14
14
  type RadialLayoutOptions,
15
15
  } from '@antv/layout';
16
- import { createBindingId, createShapeId, type Editor, type SerializedStore, type TLRecord } from '@tldraw/tldraw';
16
+ import { type Editor, type SerializedStore, type TLRecord, createBindingId, createShapeId } from '@tldraw/tldraw';
17
17
 
18
18
  import { faker } from '@dxos/random';
19
- import { isNotFalsy, range } from '@dxos/util';
19
+ import { isTruthy, range } from '@dxos/util';
20
20
 
21
21
  // TODO(burdon): Graph layout:
22
22
  // - https://www.npmjs.com/package/@antv/layout (uses d3)
@@ -67,7 +67,7 @@ export const generateGraph = (): Graph<PlainObject, PlainObject> => {
67
67
  }
68
68
  return target;
69
69
  })
70
- .filter(isNotFalsy);
70
+ .filter(isTruthy);
71
71
 
72
72
  for (const target of targets) {
73
73
  traverse(target);