@dxos/plugin-debug 0.7.2-main.f1adc9f → 0.7.2

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 (29) hide show
  1. package/dist/lib/browser/{DebugSpace-HK2GQYIB.mjs → DebugSpace-ZLGGNDAR.mjs} +3 -3
  2. package/dist/lib/browser/{DebugSpace-HK2GQYIB.mjs.map → DebugSpace-ZLGGNDAR.mjs.map} +2 -2
  3. package/dist/lib/browser/index.mjs +34 -35
  4. package/dist/lib/browser/index.mjs.map +3 -3
  5. package/dist/lib/browser/meta.json +1 -1
  6. package/dist/types/src/DebugPlugin.d.ts.map +1 -1
  7. package/dist/types/src/components/DebugObjectPanel.d.ts.map +1 -1
  8. package/dist/types/src/components/{DebugSurface.d.ts → SurfaceDebug.d.ts} +2 -2
  9. package/dist/types/src/components/{DebugSurface.d.ts.map → SurfaceDebug.d.ts.map} +1 -1
  10. package/dist/types/src/components/index.d.ts +0 -1
  11. package/dist/types/src/components/index.d.ts.map +1 -1
  12. package/package.json +38 -41
  13. package/src/DebugPlugin.tsx +39 -58
  14. package/src/components/DebugObjectPanel.tsx +1 -2
  15. package/src/components/DebugSpace/DebugSpace.tsx +1 -1
  16. package/src/components/DebugSpace/ObjectCreator.tsx +1 -1
  17. package/src/components/{DebugSurface.tsx → SurfaceDebug.tsx} +1 -1
  18. package/src/components/index.ts +0 -1
  19. package/dist/lib/browser/SpaceGenerator-TIBUROQA.mjs +0 -155
  20. package/dist/lib/browser/SpaceGenerator-TIBUROQA.mjs.map +0 -7
  21. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts +0 -9
  22. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.d.ts.map +0 -1
  23. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.stories.d.ts +0 -6
  24. package/dist/types/src/components/SpaceGenerator/SpaceGenerator.stories.d.ts.map +0 -1
  25. package/dist/types/src/components/SpaceGenerator/index.d.ts +0 -3
  26. package/dist/types/src/components/SpaceGenerator/index.d.ts.map +0 -1
  27. package/src/components/SpaceGenerator/SpaceGenerator.stories.tsx +0 -37
  28. package/src/components/SpaceGenerator/SpaceGenerator.tsx +0 -169
  29. package/src/components/SpaceGenerator/index.ts +0 -7
@@ -1,155 +0,0 @@
1
- // packages/plugins/plugin-debug/src/components/SpaceGenerator/SpaceGenerator.tsx
2
- import React, { useCallback, useMemo, useState } from "react";
3
- import { create } from "@dxos/echo-schema";
4
- import { DocumentType } from "@dxos/plugin-markdown/types";
5
- import { SheetType } from "@dxos/plugin-sheet/types";
6
- import { DiagramType } from "@dxos/plugin-sketch/types";
7
- import { faker } from "@dxos/random";
8
- import { useClient } from "@dxos/react-client";
9
- import { Filter, getTypename } from "@dxos/react-client/echo";
10
- import { IconButton, Toolbar, useAsyncEffect } from "@dxos/react-ui";
11
- import { SyntaxHighlighter } from "@dxos/react-ui-syntax-highlighter";
12
- import { TableType } from "@dxos/react-ui-table";
13
- import { createView } from "@dxos/schema";
14
- import { createAsyncGenerator, Test } from "@dxos/schema/testing";
15
- import { jsonKeyReplacer, sortKeys } from "@dxos/util";
16
- var generator = faker;
17
- var SpaceGenerator = ({ space, onAddObjects }) => {
18
- const client = useClient();
19
- const staticTypes = [
20
- DocumentType,
21
- DiagramType,
22
- SheetType
23
- ];
24
- const mutableTypes = [
25
- Test.OrgType,
26
- Test.ProjectType,
27
- Test.ContactType
28
- ];
29
- const [info, setInfo] = useState({});
30
- const typeMap = useMemo(() => {
31
- client.addTypes([
32
- DiagramType,
33
- TableType,
34
- SheetType
35
- ]);
36
- return new Map(mutableTypes.map((type) => {
37
- return [
38
- type.typename,
39
- async (n) => {
40
- const mutableSchema = await space.db.schemaRegistry.query();
41
- const schema = mutableSchema.find((schema2) => schema2.typename === type.typename) ?? space.db.schemaRegistry.addSchema(type);
42
- const generate = createAsyncGenerator(generator, schema.schema, space.db);
43
- const objects = await generate.createObjects(n);
44
- const { objects: tables } = await space.db.query(Filter.schema(TableType)).run();
45
- const table = tables.find((table2) => table2.view?.query?.typename === type.typename);
46
- if (!table) {
47
- const name = type.typename.split("/").pop() ?? type.typename;
48
- const table2 = space.db.add(create(TableType, {
49
- name,
50
- view: createView({
51
- name,
52
- typename: type.typename,
53
- jsonSchema: schema.jsonSchema
54
- })
55
- }));
56
- onAddObjects?.([
57
- table2
58
- ]);
59
- }
60
- return objects;
61
- }
62
- ];
63
- }));
64
- }, [
65
- client,
66
- mutableTypes
67
- ]);
68
- const updateInfo = async () => {
69
- const mutableSchema = await space.db.schemaRegistry.query();
70
- const staticSchema = space.db.graph.schemaRegistry.schemas;
71
- const { objects } = await space.db.query().run();
72
- const objectMap = sortKeys(objects.reduce((map, obj) => {
73
- const type = getTypename(obj);
74
- if (type) {
75
- const count = map[type] ?? 0;
76
- map[type] = count + 1;
77
- }
78
- return map;
79
- }, {}));
80
- setInfo({
81
- schema: {
82
- static: staticSchema.length,
83
- mutable: mutableSchema.length
84
- },
85
- objects: objectMap
86
- });
87
- };
88
- useAsyncEffect(updateInfo, [
89
- space
90
- ]);
91
- const handleCreateData = useCallback(async (typename) => {
92
- await typeMap.get(typename)?.(10);
93
- await updateInfo();
94
- }, [
95
- typeMap
96
- ]);
97
- return /* @__PURE__ */ React.createElement("div", {
98
- role: "none",
99
- className: "flex flex-col divide-y divide-separator"
100
- }, /* @__PURE__ */ React.createElement(Toolbar.Root, {
101
- classNames: "p-1"
102
- }, /* @__PURE__ */ React.createElement(IconButton, {
103
- icon: "ph--arrow-clockwise--regular",
104
- iconOnly: true,
105
- label: "Refresh",
106
- onClick: updateInfo
107
- })), /* @__PURE__ */ React.createElement(SchemaTable, {
108
- types: staticTypes,
109
- objects: info.objects,
110
- label: "Static Types",
111
- onClick: handleCreateData
112
- }), /* @__PURE__ */ React.createElement(SchemaTable, {
113
- types: mutableTypes,
114
- objects: info.objects,
115
- label: "Mutable Types",
116
- onClick: handleCreateData
117
- }), /* @__PURE__ */ React.createElement(SyntaxHighlighter, {
118
- classNames: "flex text-xs",
119
- language: "json"
120
- }, JSON.stringify({
121
- space,
122
- ...info
123
- }, jsonKeyReplacer({
124
- truncate: true
125
- }), 2)));
126
- };
127
- var SchemaTable = ({ types, objects = {}, label, onClick }) => {
128
- return /* @__PURE__ */ React.createElement("div", {
129
- className: "grid grid-cols-[1fr_80px_40px] gap-1 overflow-hidden"
130
- }, /* @__PURE__ */ React.createElement("div", {
131
- className: "grid grid-cols-subgrid col-span-3"
132
- }, /* @__PURE__ */ React.createElement("div", {
133
- className: "px-2 py-1 text-sm text-primary-500"
134
- }, label)), types.map((type) => /* @__PURE__ */ React.createElement("div", {
135
- key: type.typename,
136
- className: "grid grid-cols-subgrid col-span-3 items-center"
137
- }, /* @__PURE__ */ React.createElement("div", {
138
- className: "px-2 py-1 text-sm font-mono text-green-500"
139
- }, type.typename), /* @__PURE__ */ React.createElement("div", {
140
- className: "px-2 py-1 text-right font-mono"
141
- }, objects[type.typename] ?? 0), /* @__PURE__ */ React.createElement(IconButton, {
142
- variant: "ghost",
143
- icon: "ph--plus--regular",
144
- iconOnly: true,
145
- label: "Create data",
146
- onClick: () => onClick(type.typename)
147
- }))));
148
- };
149
-
150
- // packages/plugins/plugin-debug/src/components/SpaceGenerator/index.ts
151
- var SpaceGenerator_default = SpaceGenerator;
152
- export {
153
- SpaceGenerator_default as default
154
- };
155
- //# sourceMappingURL=SpaceGenerator-TIBUROQA.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/SpaceGenerator/SpaceGenerator.tsx", "../../../src/components/SpaceGenerator/index.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport React, { useCallback, useMemo, useState } from 'react';\n\nimport { create, type ReactiveObject, type BaseObject } from '@dxos/echo-schema';\nimport { DocumentType } from '@dxos/plugin-markdown/types';\nimport { SheetType } from '@dxos/plugin-sheet/types';\nimport { DiagramType } from '@dxos/plugin-sketch/types';\nimport { faker } from '@dxos/random';\nimport { useClient } from '@dxos/react-client';\nimport { Filter, getTypename, type Space } from '@dxos/react-client/echo';\nimport { IconButton, Toolbar, useAsyncEffect } from '@dxos/react-ui';\nimport { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';\nimport { TableType } from '@dxos/react-ui-table';\nimport { createView } from '@dxos/schema';\nimport { createAsyncGenerator, Test, type ValueGenerator } from '@dxos/schema/testing';\nimport { jsonKeyReplacer, sortKeys } from '@dxos/util';\n\nconst generator: ValueGenerator = faker as any;\n\n// TODO(burdon): Create docs.\n// TODO(burdon): Create sketches.\n// TODO(burdon): Create sheets.\n// TODO(burdon): Create comments.\n\nexport type SpaceGeneratorProps = {\n space: Space;\n onAddObjects?: (objects: ReactiveObject<any>[]) => void;\n};\n\n// TODO(burdon): Reuse in testbench-app.\n// TODO(burdon): Mutator running in background (factor out): from echo-generator.\nexport const SpaceGenerator = ({ space, onAddObjects }: SpaceGeneratorProps) => {\n const client = useClient();\n const staticTypes = [DocumentType, DiagramType, SheetType]; // TODO(burdon): Make extensible.\n const mutableTypes = [Test.OrgType, Test.ProjectType, Test.ContactType];\n const [info, setInfo] = useState<any>({});\n\n // Create type generators.\n const typeMap = useMemo(() => {\n client.addTypes([DiagramType, TableType, SheetType]);\n\n return new Map<string, (n: number) => Promise<BaseObject<any>>>(\n mutableTypes.map((type) => {\n return [\n type.typename,\n async (n: number) => {\n // Find or create mutable schema.\n const mutableSchema = await space.db.schemaRegistry.query();\n const schema =\n mutableSchema.find((schema) => schema.typename === type.typename) ??\n space.db.schemaRegistry.addSchema(type);\n\n // Create objects.\n const generate = createAsyncGenerator(generator, schema.schema, space.db);\n const objects = await generate.createObjects(n);\n\n // Find or create table and view.\n const { objects: tables } = await space.db.query(Filter.schema(TableType)).run();\n const table = tables.find((table) => table.view?.query?.typename === type.typename);\n if (!table) {\n const name = type.typename.split('/').pop() ?? type.typename;\n const table = space.db.add(\n create(TableType, {\n name,\n view: createView({\n name,\n typename: type.typename,\n jsonSchema: schema.jsonSchema,\n }),\n }),\n );\n\n // Add to UX.\n onAddObjects?.([table]);\n }\n\n return objects;\n },\n ];\n }),\n );\n }, [client, mutableTypes]);\n\n // Query space to get info.\n const updateInfo = async () => {\n // Create schema map.\n const mutableSchema = await space.db.schemaRegistry.query();\n const staticSchema = space.db.graph.schemaRegistry.schemas;\n\n // Create object map.\n const { objects } = await space.db.query().run();\n const objectMap = sortKeys(\n objects.reduce<Record<string, number>>((map, obj) => {\n const type = getTypename(obj);\n if (type) {\n const count = map[type] ?? 0;\n map[type] = count + 1;\n }\n return map;\n }, {}),\n );\n\n setInfo({\n schema: {\n static: staticSchema.length,\n mutable: mutableSchema.length,\n },\n objects: objectMap,\n });\n };\n\n useAsyncEffect(updateInfo, [space]);\n\n const handleCreateData = useCallback(\n async (typename: string) => {\n await typeMap.get(typename)?.(10);\n await updateInfo();\n },\n [typeMap],\n );\n\n return (\n <div role='none' className='flex flex-col divide-y divide-separator'>\n <Toolbar.Root classNames='p-1'>\n <IconButton icon='ph--arrow-clockwise--regular' iconOnly label='Refresh' onClick={updateInfo} />\n </Toolbar.Root>\n\n <SchemaTable types={staticTypes} objects={info.objects} label='Static Types' onClick={handleCreateData} />\n <SchemaTable types={mutableTypes} objects={info.objects} label='Mutable Types' onClick={handleCreateData} />\n\n <SyntaxHighlighter classNames='flex text-xs' language='json'>\n {JSON.stringify({ space, ...info }, jsonKeyReplacer({ truncate: true }), 2)}\n </SyntaxHighlighter>\n </div>\n );\n};\n\ntype SchemaTableProps = {\n types: any[];\n objects?: Record<string, number | undefined>;\n label: string;\n onClick: (typename: string) => void;\n};\n\nconst SchemaTable = ({ types, objects = {}, label, onClick }: SchemaTableProps) => {\n return (\n <div className='grid grid-cols-[1fr_80px_40px] gap-1 overflow-hidden'>\n <div className='grid grid-cols-subgrid col-span-3'>\n <div className='px-2 py-1 text-sm text-primary-500'>{label}</div>\n </div>\n {types.map((type) => (\n <div key={type.typename} className='grid grid-cols-subgrid col-span-3 items-center'>\n <div className='px-2 py-1 text-sm font-mono text-green-500'>{type.typename}</div>\n <div className='px-2 py-1 text-right font-mono'>{objects[type.typename] ?? 0}</div>\n <IconButton\n variant='ghost'\n icon='ph--plus--regular'\n iconOnly\n label='Create data'\n onClick={() => onClick(type.typename)}\n />\n </div>\n ))}\n </div>\n );\n};\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { SpaceGenerator } from './SpaceGenerator';\n\nexport default SpaceGenerator;\n"],
5
- "mappings": ";AAIA,OAAOA,SAASC,aAAaC,SAASC,gBAAgB;AAEtD,SAASC,cAAoD;AAC7D,SAASC,oBAAoB;AAC7B,SAASC,iBAAiB;AAC1B,SAASC,mBAAmB;AAC5B,SAASC,aAAa;AACtB,SAASC,iBAAiB;AAC1B,SAASC,QAAQC,mBAA+B;AAChD,SAASC,YAAYC,SAASC,sBAAsB;AACpD,SAASC,yBAAyB;AAClC,SAASC,iBAAiB;AAC1B,SAASC,kBAAkB;AAC3B,SAASC,sBAAsBC,YAAiC;AAChE,SAASC,iBAAiBC,gBAAgB;AAE1C,IAAMC,YAA4BC;AAc3B,IAAMC,iBAAiB,CAAC,EAAEC,OAAOC,aAAY,MAAuB;AACzE,QAAMC,SAASC,UAAAA;AACf,QAAMC,cAAc;IAACC;IAAcC;IAAaC;;AAChD,QAAMC,eAAe;IAACC,KAAKC;IAASD,KAAKE;IAAaF,KAAKG;;AAC3D,QAAM,CAACC,MAAMC,OAAAA,IAAWC,SAAc,CAAC,CAAA;AAGvC,QAAMC,UAAUC,QAAQ,MAAA;AACtBf,WAAOgB,SAAS;MAACZ;MAAaa;MAAWZ;KAAU;AAEnD,WAAO,IAAIa,IACTZ,aAAaa,IAAI,CAACC,SAAAA;AAChB,aAAO;QACLA,KAAKC;QACL,OAAOC,MAAAA;AAEL,gBAAMC,gBAAgB,MAAMzB,MAAM0B,GAAGC,eAAeC,MAAK;AACzD,gBAAMC,SACJJ,cAAcK,KAAK,CAACD,YAAWA,QAAON,aAAaD,KAAKC,QAAQ,KAChEvB,MAAM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C,OAAAA;IAAIE,WAAU;KAAkCjC,QAAQZ,KAAKC,QAAQ,KAAK,CAAA,GAC3E,sBAAA,cAACgD,YAAAA;IACCc,SAAQ;IACRb,MAAK;IACLC,UAAAA;IACAC,OAAM;IACNC,SAAS,MAAMA,QAAQrD,KAAKC,QAAQ;;AAMhD;;;AClKA,IAAA,yBAAe+D;",
6
- "names": ["React", "useCallback", "useMemo", "useState", "create", "DocumentType", "SheetType", "DiagramType", "faker", "useClient", "Filter", "getTypename", "IconButton", "Toolbar", "useAsyncEffect", "SyntaxHighlighter", "TableType", "createView", "createAsyncGenerator", "Test", "jsonKeyReplacer", "sortKeys", "generator", "faker", "SpaceGenerator", "space", "onAddObjects", "client", "useClient", "staticTypes", "DocumentType", "DiagramType", "SheetType", "mutableTypes", "Test", "OrgType", "ProjectType", "ContactType", "info", "setInfo", "useState", "typeMap", "useMemo", "addTypes", "TableType", "Map", "map", "type", "typename", "n", "mutableSchema", "db", "schemaRegistry", "query", "schema", "find", "addSchema", "generate", "createAsyncGenerator", "objects", "createObjects", "tables", "Filter", "run", "table", "view", "name", "split", "pop", "add", "create", "createView", "jsonSchema", "updateInfo", "staticSchema", "graph", "schemas", "objectMap", "sortKeys", "reduce", "obj", "getTypename", "count", "static", "length", "mutable", "useAsyncEffect", "handleCreateData", "useCallback", "get", "div", "role", "className", "Toolbar", "Root", "classNames", "IconButton", "icon", "iconOnly", "label", "onClick", "SchemaTable", "types", "SyntaxHighlighter", "language", "JSON", "stringify", "jsonKeyReplacer", "truncate", "key", "variant", "SpaceGenerator"]
7
- }
@@ -1,9 +0,0 @@
1
- import React from 'react';
2
- import { type ReactiveObject } from '@dxos/echo-schema';
3
- import { type Space } from '@dxos/react-client/echo';
4
- export type SpaceGeneratorProps = {
5
- space: Space;
6
- onAddObjects?: (objects: ReactiveObject<any>[]) => void;
7
- };
8
- export declare const SpaceGenerator: ({ space, onAddObjects }: SpaceGeneratorProps) => React.JSX.Element;
9
- //# sourceMappingURL=SpaceGenerator.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SpaceGenerator.d.ts","sourceRoot":"","sources":["../../../../../src/components/SpaceGenerator/SpaceGenerator.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAyC,MAAM,OAAO,CAAC;AAE9D,OAAO,EAAU,KAAK,cAAc,EAAmB,MAAM,mBAAmB,CAAC;AAMjF,OAAO,EAAuB,KAAK,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAe1E,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,EAAE,KAAK,CAAC;IACb,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,cAAc,CAAC,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC;CACzD,CAAC;AAIF,eAAO,MAAM,cAAc,4BAA6B,mBAAmB,sBAwG1E,CAAC"}
@@ -1,6 +0,0 @@
1
- import '@dxos-theme';
2
- import { type Meta } from '@storybook/react';
3
- declare const meta: Meta;
4
- export default meta;
5
- export declare const Default: {};
6
- //# sourceMappingURL=SpaceGenerator.stories.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SpaceGenerator.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/SpaceGenerator/SpaceGenerator.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,aAAa,CAAC;AAErB,OAAO,EAAE,KAAK,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAkB7C,QAAA,MAAM,IAAI,EAAE,IAQX,CAAC;AAEF,eAAe,IAAI,CAAC;AAEpB,eAAO,MAAM,OAAO,IAAK,CAAC"}
@@ -1,3 +0,0 @@
1
- import { SpaceGenerator } from './SpaceGenerator';
2
- export default SpaceGenerator;
3
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/SpaceGenerator/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,eAAe,cAAc,CAAC"}
@@ -1,37 +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 { useSpaces } from '@dxos/react-client/echo';
11
- import { withClientProvider } from '@dxos/react-client/testing';
12
- import { render, withLayout, withTheme } from '@dxos/storybook-utils';
13
-
14
- import { SpaceGenerator } from './SpaceGenerator';
15
-
16
- const DefaultStory = () => {
17
- const [space] = useSpaces();
18
- if (!space) {
19
- return null;
20
- }
21
-
22
- return <SpaceGenerator space={space} />;
23
- };
24
-
25
- const meta: Meta = {
26
- title: 'plugins/plugin-debug/SpaceGenerator',
27
- component: SpaceGenerator,
28
- render: render(DefaultStory),
29
- decorators: [withClientProvider({ createSpace: true }), withLayout({ tooltips: true }), withTheme],
30
- parameters: {
31
- layout: 'fullscreen',
32
- },
33
- };
34
-
35
- export default meta;
36
-
37
- export const Default = {};
@@ -1,169 +0,0 @@
1
- //
2
- // Copyright 2024 DXOS.org
3
- //
4
-
5
- import React, { useCallback, useMemo, useState } from 'react';
6
-
7
- import { create, type ReactiveObject, type BaseObject } from '@dxos/echo-schema';
8
- import { DocumentType } from '@dxos/plugin-markdown/types';
9
- import { SheetType } from '@dxos/plugin-sheet/types';
10
- import { DiagramType } from '@dxos/plugin-sketch/types';
11
- import { faker } from '@dxos/random';
12
- import { useClient } from '@dxos/react-client';
13
- import { Filter, getTypename, type Space } from '@dxos/react-client/echo';
14
- import { IconButton, Toolbar, useAsyncEffect } from '@dxos/react-ui';
15
- import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
16
- import { TableType } from '@dxos/react-ui-table';
17
- import { createView } from '@dxos/schema';
18
- import { createAsyncGenerator, Test, type ValueGenerator } from '@dxos/schema/testing';
19
- import { jsonKeyReplacer, sortKeys } from '@dxos/util';
20
-
21
- const generator: ValueGenerator = faker as any;
22
-
23
- // TODO(burdon): Create docs.
24
- // TODO(burdon): Create sketches.
25
- // TODO(burdon): Create sheets.
26
- // TODO(burdon): Create comments.
27
-
28
- export type SpaceGeneratorProps = {
29
- space: Space;
30
- onAddObjects?: (objects: ReactiveObject<any>[]) => void;
31
- };
32
-
33
- // TODO(burdon): Reuse in testbench-app.
34
- // TODO(burdon): Mutator running in background (factor out): from echo-generator.
35
- export const SpaceGenerator = ({ space, onAddObjects }: SpaceGeneratorProps) => {
36
- const client = useClient();
37
- const staticTypes = [DocumentType, DiagramType, SheetType]; // TODO(burdon): Make extensible.
38
- const mutableTypes = [Test.OrgType, Test.ProjectType, Test.ContactType];
39
- const [info, setInfo] = useState<any>({});
40
-
41
- // Create type generators.
42
- const typeMap = useMemo(() => {
43
- client.addTypes([DiagramType, TableType, SheetType]);
44
-
45
- return new Map<string, (n: number) => Promise<BaseObject<any>>>(
46
- mutableTypes.map((type) => {
47
- return [
48
- type.typename,
49
- async (n: number) => {
50
- // Find or create mutable schema.
51
- const mutableSchema = await space.db.schemaRegistry.query();
52
- const schema =
53
- mutableSchema.find((schema) => schema.typename === type.typename) ??
54
- space.db.schemaRegistry.addSchema(type);
55
-
56
- // Create objects.
57
- const generate = createAsyncGenerator(generator, schema.schema, space.db);
58
- const objects = await generate.createObjects(n);
59
-
60
- // Find or create table and view.
61
- const { objects: tables } = await space.db.query(Filter.schema(TableType)).run();
62
- const table = tables.find((table) => table.view?.query?.typename === type.typename);
63
- if (!table) {
64
- const name = type.typename.split('/').pop() ?? type.typename;
65
- const table = space.db.add(
66
- create(TableType, {
67
- name,
68
- view: createView({
69
- name,
70
- typename: type.typename,
71
- jsonSchema: schema.jsonSchema,
72
- }),
73
- }),
74
- );
75
-
76
- // Add to UX.
77
- onAddObjects?.([table]);
78
- }
79
-
80
- return objects;
81
- },
82
- ];
83
- }),
84
- );
85
- }, [client, mutableTypes]);
86
-
87
- // Query space to get info.
88
- const updateInfo = async () => {
89
- // Create schema map.
90
- const mutableSchema = await space.db.schemaRegistry.query();
91
- const staticSchema = space.db.graph.schemaRegistry.schemas;
92
-
93
- // Create object map.
94
- const { objects } = await space.db.query().run();
95
- const objectMap = sortKeys(
96
- objects.reduce<Record<string, number>>((map, obj) => {
97
- const type = getTypename(obj);
98
- if (type) {
99
- const count = map[type] ?? 0;
100
- map[type] = count + 1;
101
- }
102
- return map;
103
- }, {}),
104
- );
105
-
106
- setInfo({
107
- schema: {
108
- static: staticSchema.length,
109
- mutable: mutableSchema.length,
110
- },
111
- objects: objectMap,
112
- });
113
- };
114
-
115
- useAsyncEffect(updateInfo, [space]);
116
-
117
- const handleCreateData = useCallback(
118
- async (typename: string) => {
119
- await typeMap.get(typename)?.(10);
120
- await updateInfo();
121
- },
122
- [typeMap],
123
- );
124
-
125
- return (
126
- <div role='none' className='flex flex-col divide-y divide-separator'>
127
- <Toolbar.Root classNames='p-1'>
128
- <IconButton icon='ph--arrow-clockwise--regular' iconOnly label='Refresh' onClick={updateInfo} />
129
- </Toolbar.Root>
130
-
131
- <SchemaTable types={staticTypes} objects={info.objects} label='Static Types' onClick={handleCreateData} />
132
- <SchemaTable types={mutableTypes} objects={info.objects} label='Mutable Types' onClick={handleCreateData} />
133
-
134
- <SyntaxHighlighter classNames='flex text-xs' language='json'>
135
- {JSON.stringify({ space, ...info }, jsonKeyReplacer({ truncate: true }), 2)}
136
- </SyntaxHighlighter>
137
- </div>
138
- );
139
- };
140
-
141
- type SchemaTableProps = {
142
- types: any[];
143
- objects?: Record<string, number | undefined>;
144
- label: string;
145
- onClick: (typename: string) => void;
146
- };
147
-
148
- const SchemaTable = ({ types, objects = {}, label, onClick }: SchemaTableProps) => {
149
- return (
150
- <div className='grid grid-cols-[1fr_80px_40px] gap-1 overflow-hidden'>
151
- <div className='grid grid-cols-subgrid col-span-3'>
152
- <div className='px-2 py-1 text-sm text-primary-500'>{label}</div>
153
- </div>
154
- {types.map((type) => (
155
- <div key={type.typename} className='grid grid-cols-subgrid col-span-3 items-center'>
156
- <div className='px-2 py-1 text-sm font-mono text-green-500'>{type.typename}</div>
157
- <div className='px-2 py-1 text-right font-mono'>{objects[type.typename] ?? 0}</div>
158
- <IconButton
159
- variant='ghost'
160
- icon='ph--plus--regular'
161
- iconOnly
162
- label='Create data'
163
- onClick={() => onClick(type.typename)}
164
- />
165
- </div>
166
- ))}
167
- </div>
168
- );
169
- };
@@ -1,7 +0,0 @@
1
- //
2
- // Copyright 2023 DXOS.org
3
- //
4
-
5
- import { SpaceGenerator } from './SpaceGenerator';
6
-
7
- export default SpaceGenerator;