New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

mock-block-dock

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mock-block-dock - npm Package Compare versions

Comparing version

to
0.1.0-20230124234232

import { Entity } from "@blockprotocol/graph";
declare const entities: Entity[];
declare const entities: Entity<Record<string, import("@blockprotocol/graph").EntityPropertyValue>>[];
export { entities };
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.entities = void 0;
const slim_1 = require("@blockprotocol/type-system/slim");
const entity_types_1 = require("./entity-types");
const property_types_1 = require("./property-types");
const words_1 = require("./words");
const entities = [];
exports.entities = entities;
const NUMBER_OF_ENTITIES_TO_CREATE = Math.min(words_1.personNames.length, words_1.companyNames.length);
const createPerson = (entityId) => {
const now = new Date();
const name = words_1.personNames[entityId] ?? "Unknown Person";
return {
entityId: `person-${entityId.toString()}`,
entityTypeId: "Person",
metadata: {
editionId: {
baseId: `person-${entityId.toString()}`,
versionId: new Date().toISOString(),
},
entityTypeId: entity_types_1.entityTypes.person.$id,
},
properties: {
createdAt: now,
updatedAt: now,
age: Math.ceil(Math.random() * 100),
email: `${name}@example.com`,
name,
username: name.toLowerCase(),
[(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.age.$id)]: Math.ceil(Math.random() * 100),
[(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.email.$id)]: `${name}@example.com`,
[(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.name.$id)]: name,
[(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.username.$id)]: name.toLowerCase(),
},

@@ -25,19 +27,77 @@ };

const createCompany = (entityId) => {
const now = new Date();
const name = words_1.companyNames[entityId];
const name = words_1.companyNames[entityId] ?? "Unknown Company";
return {
entityId: `company-${entityId.toString()}`,
entityTypeId: "Company",
metadata: {
editionId: {
baseId: `company-${entityId.toString()}`,
versionId: new Date().toISOString(),
},
entityTypeId: entity_types_1.entityTypes.company.$id,
},
properties: {
createdAt: now,
updatedAt: now,
employees: Math.ceil(Math.random() * 10000),
name,
[(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.numberOfEmployees.$id)]: Math.ceil(Math.random() * 10000),
[(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.name.$id)]: name,
},
};
};
for (let id = 0; id < NUMBER_OF_ENTITIES_TO_CREATE; id++) {
entities.push(createCompany(id));
entities.push(createPerson(id));
}
const createWorksForLink = (sourceEntityId, destinationEntityId) => {
return {
metadata: {
editionId: {
baseId: `${sourceEntityId}-works-for-${destinationEntityId}`,
versionId: new Date().toISOString(),
},
entityTypeId: entity_types_1.entityTypes.worksFor.$id,
},
properties: {},
linkData: {
leftEntityId: sourceEntityId,
rightEntityId: destinationEntityId,
},
};
};
const createFounderOfLink = (sourceEntityId, destinationEntityId) => {
return {
metadata: {
editionId: {
baseId: `${sourceEntityId}-founder-of-${destinationEntityId}`,
versionId: new Date().toISOString(),
},
entityTypeId: entity_types_1.entityTypes.founderOf.$id,
},
properties: {},
linkData: {
leftEntityId: sourceEntityId,
rightEntityId: destinationEntityId,
},
};
};
const createEntities = () => {
// First create people and companies in separate lists
const people = [];
const companies = [];
for (let idx = 0; idx < words_1.personNames.length; idx++) {
people.push(createPerson(idx));
}
for (let idx = 0; idx < words_1.companyNames.length; idx++) {
companies.push(createCompany(idx));
}
const entities = [];
// For each company, `pop` (to avoid double selection in the next step) a person to be the founder, and start building
// the final entities list
for (const company of companies) {
const founder = people.pop();
if (founder) {
entities.push(createFounderOfLink(founder.metadata.editionId.baseId, company.metadata.editionId.baseId));
entities.push(founder);
}
}
for (const person of people) {
entities.push(createWorksForLink(person.metadata.editionId.baseId, companies[Math.floor(Math.random() * companies.length)].metadata
.editionId.baseId));
}
return [...entities, ...people, ...companies];
};
const entities = createEntities();
exports.entities = entities;
//# sourceMappingURL=entities.js.map
import { EntityType } from "@blockprotocol/graph";
export declare const entityTypes: EntityType[];
export declare const entityTypes: {
company: EntityType;
person: EntityType;
worksFor: EntityType;
founderOf: EntityType;
testType: EntityType;
};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.entityTypes = void 0;
exports.entityTypes = [
{
entityTypeId: "Company",
schema: {
$id: "https://example.com/types/Company",
title: "Company",
type: "object",
$schema: "https://json-schema.org/draft/2019-09/schema",
description: "A company or organisation.",
properties: {
employees: {
type: "number",
description: "The number of employees in the company.",
},
name: {
type: "string",
description: "A display name for the company.",
},
},
labelProperty: "name",
required: ["name", "employees"],
const slim_1 = require("@blockprotocol/type-system/slim");
const property_types_1 = require("./property-types");
const worksFor = {
kind: "entityType",
$id: "https://example.com/types/entity-type/works-for/v/1",
type: "object",
title: "Works For",
description: "Has employment at this entity.",
allOf: [
{
$ref: "https://blockprotocol.org/@blockprotocol/types/entity-type/link/v/1",
},
],
properties: {},
required: [],
};
const founderOf = {
kind: "entityType",
$id: "https://example.com/types/entity-type/founder-of/v/1",
type: "object",
title: "Founder of",
description: "Established this entity.",
allOf: [
{
$ref: "https://blockprotocol.org/@blockprotocol/types/entity-type/link/v/1",
},
],
properties: {},
required: [],
};
const company = {
kind: "entityType",
$id: "https://example.com/types/entity-type/company/v/1",
type: "object",
title: "Company",
description: "A company or organization.",
properties: {
[(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.numberOfEmployees.$id)]: {
$ref: property_types_1.propertyTypes.numberOfEmployees.$id,
},
[(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.name.$id)]: {
$ref: property_types_1.propertyTypes.name.$id,
},
},
{
entityTypeId: "Person",
schema: {
$id: "https://example.com/types/Person",
title: "Person",
type: "object",
$schema: "https://json-schema.org/draft/2019-09/schema",
description: "A human person.",
properties: {
age: {
type: "number",
description: "The age of the person, in years.",
},
email: {
type: "string",
description: "An email address.",
format: "email",
},
name: {
type: "string",
description: "The person's name.",
},
username: {
description: "The person's username in this application",
type: "string",
minLength: 4,
maxLength: 24,
},
required: [
(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.numberOfEmployees.$id),
(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.name.$id),
],
links: {},
};
const person = {
kind: "entityType",
$id: "https://example.com/types/entity-type/person/v/1",
type: "object",
title: "Person",
description: "A human person.",
properties: {
[(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.age.$id)]: {
$ref: property_types_1.propertyTypes.age.$id,
},
[(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.email.$id)]: {
$ref: property_types_1.propertyTypes.email.$id,
},
[(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.name.$id)]: {
$ref: property_types_1.propertyTypes.name.$id,
},
[(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.username.$id)]: {
$ref: property_types_1.propertyTypes.username.$id,
},
},
required: [
(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.age.$id),
(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.email.$id),
(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.name.$id),
(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.username.$id),
],
links: {
[worksFor.$id]: {
type: "array",
items: {
$ref: company.$id,
},
labelProperty: "name",
required: ["age", "email", "name", "username"],
ordered: false,
},
[founderOf.$id]: {
type: "array",
items: {
$ref: company.$id,
},
ordered: false,
},
},
];
};
const testType = {
kind: "entityType",
$id: "https://example.com/types/entity-type/test-type/v/1",
type: "object",
title: "Test Type",
description: "A Type for Testing",
properties: {
[(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.name.$id)]: {
$ref: property_types_1.propertyTypes.name.$id,
},
},
required: [(0, slim_1.extractBaseUri)(property_types_1.propertyTypes.name.$id)],
links: {},
};
exports.entityTypes = {
company,
person,
worksFor,
founderOf,
testType,
};
// satisfies Record<string, EntityType> };
//# sourceMappingURL=entity-types.js.map

@@ -1,2 +0,2 @@

import { MockData } from "../use-mock-block-props/use-mock-datastore";
import { MockData } from "../datastore/use-mock-datastore";
export declare const mockData: MockData;

@@ -5,11 +5,6 @@ "use strict";

const entities_1 = require("./entities");
const entity_types_1 = require("./entity-types");
const linked_aggregation_definitions_1 = require("./linked-aggregation-definitions");
const links_1 = require("./links");
exports.mockData = {
entities: entities_1.entities,
entityTypes: entity_types_1.entityTypes,
links: links_1.links,
linkedAggregationDefinitions: linked_aggregation_definitions_1.linkedAggregationDefinitions,
// linkedAggregationDefinitions,
};
//# sourceMappingURL=index.js.map

@@ -18,2 +18,6 @@ "use strict";

"Louis",
"Alice",
"Johanna",
"Jeremy",
"Samuel",
];

@@ -20,0 +24,0 @@ exports.companyNames = [

/// <reference types="react" />
export declare const BlockSchemaView: () => JSX.Element | null;
import { EntityType } from "@blockprotocol/graph";
export declare const BlockSchemaView: ({ entityType }: {
entityType: EntityType;
}) => JSX.Element;

@@ -6,12 +6,7 @@ "use strict";

const material_1 = require("@mui/material");
const mock_block_dock_context_1 = require("../../mock-block-dock-context");
const json_view_1 = require("./json-view");
const BlockSchemaView = () => {
const { blockSchema } = (0, mock_block_dock_context_1.useMockBlockDockContext)();
if (!blockSchema) {
return null;
}
return ((0, jsx_runtime_1.jsx)(material_1.Box, { maxWidth: 800, children: (0, jsx_runtime_1.jsx)(json_view_1.JsonView, { collapseKeys: Object.keys(blockSchema), rootName: "blockSchema", src: blockSchema }) }));
const BlockSchemaView = ({ entityType }) => {
return ((0, jsx_runtime_1.jsx)(material_1.Box, { maxWidth: 800, children: (0, jsx_runtime_1.jsx)(json_view_1.JsonView, { collapseKeys: Object.keys(entityType), rootName: "blockSchema", src: entityType }) }));
};
exports.BlockSchemaView = BlockSchemaView;
//# sourceMappingURL=block-schema-view.js.map

@@ -7,6 +7,6 @@ "use strict";

const mock_block_dock_context_1 = require("../../mock-block-dock-context");
const datastore_graph_visualisation_1 = require("./datastore-graph-visualisation");
const datastore_graph_visualization_1 = require("./datastore-graph-visualization");
const json_view_1 = require("./json-view");
const DataStoreView = () => {
const { datastore } = (0, mock_block_dock_context_1.useMockBlockDockContext)();
const { graph } = (0, mock_block_dock_context_1.useMockBlockDockContext)();
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {

@@ -19,15 +19,8 @@ minHeight: "100%",

},
}, children: [(0, jsx_runtime_1.jsx)(json_view_1.JsonView, { collapseKeys: [
"entities",
"entityTypes",
"links",
"linkedAggregations",
], rootName: "datastore", src: {
entities: datastore.entities,
entityTypes: datastore.entityTypes,
links: datastore.links,
linkedAggregations: datastore.linkedAggregationDefinitions,
} }), (0, jsx_runtime_1.jsx)(datastore_graph_visualisation_1.DatastoreGraphVisualisation, {})] }));
}, children: [(0, jsx_runtime_1.jsx)(json_view_1.JsonView, { collapseKeys: ["vertices", "edges"], rootName: "datastore", src: {
vertices: graph.vertices,
edges: graph.edges,
} }), (0, jsx_runtime_1.jsx)(datastore_graph_visualization_1.DatastoreGraphVisualization, {})] }));
};
exports.DataStoreView = DataStoreView;
//# sourceMappingURL=datastore-view.js.map

@@ -5,2 +5,3 @@ "use strict";

const jsx_runtime_1 = require("react/jsx-runtime");
const stdlib_1 = require("@blockprotocol/graph/stdlib");
const material_1 = require("@mui/material");

@@ -18,6 +19,7 @@ const react_1 = require("react");

const [anchorEl, setAnchorEl] = (0, react_1.useState)(null);
const { blockEntity, setEntityIdOfEntityForBlock, datastore } = (0, mock_block_dock_context_1.useMockBlockDockContext)();
const [entityTypeId, setEntityTypeId] = (0, react_1.useState)(blockEntity.entityTypeId);
const [entityId, setEntityIdOfProposedEntityForBlock] = (0, react_1.useState)(blockEntity.entityId);
const selectedEntity = datastore.entities.find((entity) => entity.entityId === entityId && entity.entityTypeId === entityTypeId);
const { blockEntitySubgraph, setEntityEditionIdOfEntityForBlock, graph } = (0, mock_block_dock_context_1.useMockBlockDockContext)();
const blockEntity = (0, react_1.useMemo)(() => (0, stdlib_1.getRoots)(blockEntitySubgraph)[0], [blockEntitySubgraph]);
const [entityTypeId, setEntityTypeId] = (0, react_1.useState)(blockEntity.metadata.entityTypeId);
const [entityId, setEntityIdOfProposedEntityForBlock] = (0, react_1.useState)(blockEntity.metadata.editionId.baseId);
const selectedEntity = (0, react_1.useMemo)(() => (entityId ? (0, stdlib_1.getEntity)(graph, entityId) : blockEntity), [graph, blockEntity, entityId]);
const handleClick = (event) => {

@@ -31,3 +33,3 @@ setAnchorEl(event.currentTarget);

if (selectedEntity) {
setEntityIdOfEntityForBlock(selectedEntity.entityId);
setEntityEditionIdOfEntityForBlock(selectedEntity.metadata.editionId);
}

@@ -52,9 +54,9 @@ closePopover();

setEntityTypeId(event.target.value);
}, sx: { mb: 2 }, fullWidth: true, children: datastore.entityTypes.map((type) => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: type.entityTypeId, children: type.entityTypeId }, type.entityTypeId))) })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "label", htmlFor: "entity-id-selector", fontWeight: 500, variant: "caption", children: "Entity Id" }), (0, jsx_runtime_1.jsx)(material_1.Select, { id: "entity-id-selector", size: "small", value: entityId, placeholder: "Select Entity", onChange: (event) => {
}, sx: { mb: 2 }, fullWidth: true, children: (0, stdlib_1.getEntityTypes)(graph).map(({ schema: entityType }) => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: entityType.$id, children: entityType.$id }, entityType.$id))) })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "label", htmlFor: "entity-id-selector", fontWeight: 500, variant: "caption", children: "Entity Id" }), (0, jsx_runtime_1.jsx)(material_1.Select, { id: "entity-id-selector", size: "small", value: entityId, placeholder: "Select Entity", onChange: (event) => {
setEntityIdOfProposedEntityForBlock(event.target.value);
}, sx: {
mb: 2,
}, fullWidth: true, children: datastore.entities
.filter((entity) => entity.entityTypeId === entityTypeId)
.map((entity) => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: entity.entityId, children: entity.entityId }, entity.entityId))) })] }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", disableFocusRipple: true, disableRipple: true, sx: { textTransform: "none" }, onClick: handleSubmit, children: "Switch Entity" })] }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
}, fullWidth: true, children: (0, stdlib_1.getEntities)(graph)
.filter((entity) => entity.metadata.entityTypeId === entityTypeId)
.map((entity) => ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { value: entity.metadata.editionId.baseId, children: entity.metadata.editionId.baseId }, entity.metadata.editionId.baseId))) })] }), (0, jsx_runtime_1.jsx)(material_1.Button, { variant: "contained", disableFocusRipple: true, disableRipple: true, sx: { textTransform: "none" }, onClick: handleSubmit, children: "Switch Entity" })] }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
".react-json-view": {

@@ -65,5 +67,5 @@ height: 250,

},
}, children: (0, jsx_runtime_1.jsx)(json_view_1.JsonView, { rootName: "properties", collapseKeys: [], src: selectedEntity?.properties ?? {}, enableClipboard: false, quotesOnKeys: false, displayObjectSize: false, displayDataTypes: false }) })] })] }));
}, children: (0, jsx_runtime_1.jsx)(json_view_1.JsonView, { rootName: "properties", collapseKeys: [], src: blockEntity?.properties ?? {}, enableClipboard: false, quotesOnKeys: false, displayObjectSize: false, displayDataTypes: false }) })] })] }));
};
exports.EntitySwitcher = EntitySwitcher;
//# sourceMappingURL=entity-switcher.js.map
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PropertiesView = void 0;
const jsx_runtime_1 = require("react/jsx-runtime");
const stdlib_1 = require("@blockprotocol/graph/stdlib");
const material_1 = require("@mui/material");
const ajv_1 = __importDefault(require("ajv"));
const react_1 = require("react");
const mock_block_dock_context_1 = require("../../mock-block-dock-context");

@@ -15,42 +13,64 @@ const palette_1 = require("../theme/palette");

const json_view_1 = require("./json-view");
const ajv = new ajv_1.default();
// const ajv = new Ajv();
const PropertiesView = () => {
const { readonly, setReadonly, blockSchema, blockEntity, updateEntity } = (0, mock_block_dock_context_1.useMockBlockDockContext)();
const validate = ajv.compile(blockSchema ?? {});
validate(blockEntity.properties);
const errors = validate.errors?.map((error) => error.message);
const { readonly, setReadonly, blockEntitySubgraph, updateEntity, graph } = (0, mock_block_dock_context_1.useMockBlockDockContext)();
const blockEntity = (0, react_1.useMemo)(() => (0, stdlib_1.getRoots)(blockEntitySubgraph)[0], [blockEntitySubgraph]);
const blockEntityType = (0, react_1.useMemo)(() => (0, stdlib_1.getEntityTypeById)(graph, blockEntity.metadata.entityTypeId), [graph, blockEntity]);
/** @todo - reimplement validation */
// const validate = ajv.compile(blockSchema ?? {});
// validate(blockEntity.properties);
// const errors = validate.errors?.map((error) => error.message);
const errors = [];
return ((0, jsx_runtime_1.jsx)(material_1.Container, { maxWidth: "xl", children: (0, jsx_runtime_1.jsxs)(material_1.Grid, { container: true, children: [(0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, xs: 6, children: (0, jsx_runtime_1.jsxs)(material_1.Box, { mb: 3, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { display: "flex", justifyContent: "space-between", mb: 1 }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "subtitle2", children: "Entity Properties" }), (0, jsx_runtime_1.jsx)(entity_switcher_1.EntitySwitcher, {}), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: { display: "flex" }, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "subtitle2", mr: 1, children: "Read-only mode" }), (0, jsx_runtime_1.jsx)(material_1.Switch, { checked: readonly, onChange: (evt) => setReadonly(evt.target.checked), size: "small" })] })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { maxWidth: 800, children: [(0, jsx_runtime_1.jsx)(json_view_1.JsonView, { collapseKeys: ["graph"], rootName: "blockEntity", sortKeys: true, src: blockEntity ?? {}, onEdit: (args) => {
// These fields should not be edited
if (args.name &&
["entityType", "entityTypeId", "entityId"].includes(args.name)) {
(args.name.includes("versionId") ||
args.name.includes("baseId") ||
args.name.includes("leftEntityId") ||
args.name.includes("rightEntityId"))) {
return false;
}
const entity = args.updated_src;
void updateEntity({
data: args.updated_src,
data: {
entityId: entity.metadata.editionId.baseId,
entityTypeId: entity.metadata.entityTypeId,
properties: entity.properties,
leftToRightOrder: entity.linkData?.leftToRightOrder,
rightToLeftOrder: entity.linkData?.rightToLeftOrder,
},
});
}, onAdd: (args) => {
// don't allow adding of top level fields
if (args.name && !args.name.includes("properties")) {
if (!args.namespace.includes("properties")) {
return false;
}
const entity = args.updated_src;
void updateEntity({
data: args.updated_src,
data: {
entityId: entity.metadata.editionId.baseId,
entityTypeId: entity.metadata.entityTypeId,
properties: entity.properties,
leftToRightOrder: entity.linkData?.leftToRightOrder,
rightToLeftOrder: entity.linkData?.rightToLeftOrder,
},
});
}, onDelete: (args) => {
// These fields should not be deleted
if (args.name &&
[
"entityType",
"entityTypeId",
"entityId",
"properties",
].includes(args.name)) {
// don't allow deleting of top level fields
if (!args.namespace.includes("properties")) {
return false;
}
const entity = args.updated_src;
void updateEntity({
data: args.updated_src,
data: {
entityId: entity.metadata.editionId.baseId,
entityTypeId: entity.metadata.entityTypeId,
properties: entity.properties,
leftToRightOrder: entity.linkData?.leftToRightOrder,
rightToLeftOrder: entity.linkData?.rightToLeftOrder,
},
});
}, validationMessage: "You may only edit the properties object" }), (0, jsx_runtime_1.jsx)(material_1.Collapse, { in: !!errors?.length, children: errors?.map((error) => ((0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "subtitle2", color: palette_1.customColors.red[600], children: error }, error))) })] })] }) }), (0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, xs: 6, children: blockSchema && ((0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "subtitle2", mb: 1, children: "Block Schema" }), (0, jsx_runtime_1.jsx)(block_schema_view_1.BlockSchemaView, {})] })) })] }) }));
}, validationMessage: "You may only edit the properties object" }), (0, jsx_runtime_1.jsx)(material_1.Collapse, { in: !!errors?.length, children: errors?.map((error) => ((0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "subtitle2", color: palette_1.customColors.red[600], children: error }, error))) })] })] }) }), (0, jsx_runtime_1.jsx)(material_1.Grid, { item: true, xs: 6, children: blockEntityType && ((0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "subtitle2", mb: 1, children: "Block Schema" }), (0, jsx_runtime_1.jsx)(block_schema_view_1.BlockSchemaView, { entityType: blockEntityType.schema })] })) })] }) }));
};
exports.PropertiesView = PropertiesView;
//# sourceMappingURL=properties.js.map

@@ -5,2 +5,3 @@ "use strict";

const jsx_runtime_1 = require("react/jsx-runtime");
const stdlib_1 = require("@blockprotocol/graph/stdlib");
const react_1 = require("react");

@@ -12,5 +13,5 @@ const react_dom_1 = require("react-dom");

const HookPortal = ({ entityId, path, type }) => {
const { datastore, readonly, updateEntity } = (0, mock_block_dock_context_1.useMockBlockDockContext)();
const { graph, readonly, updateEntity } = (0, mock_block_dock_context_1.useMockBlockDockContext)();
const { entity, value } = (0, react_1.useMemo)(() => {
const foundEntity = datastore.entities.find((currentEntity) => currentEntity.entityId === entityId);
const foundEntity = (0, stdlib_1.getEntity)(graph, entityId);
if (!foundEntity) {

@@ -22,3 +23,3 @@ throw new Error(`Could not find entity requested by hook with entityId '${entityId}' in datastore.`);

return { entity: foundEntity, value: foundValue };
}, [datastore.entities, entityId, path]);
}, [graph, entityId, path]);
const updateValue = (0, react_1.useCallback)(async (newValue) => {

@@ -28,3 +29,9 @@ const newProperties = { ...entity?.properties };

return updateEntity({
data: { entityId, properties: newProperties },
data: {
entityId,
entityTypeId: entity.metadata.entityTypeId,
properties: newProperties,
leftToRightOrder: entity.linkData?.leftToRightOrder,
rightToLeftOrder: entity.linkData?.rightToLeftOrder,
},
});

@@ -31,0 +38,0 @@ }, [entity, entityId, path, updateEntity]);

import { Message } from "@blockprotocol/core";
import { EmbedderGraphMessageCallbacks, Entity, EntityType } from "@blockprotocol/graph";
import { EmbedderGraphMessageCallbacks, EntityEditionId, Subgraph, SubgraphRootTypes } from "@blockprotocol/graph";
import { Dispatch, ReactNode, SetStateAction } from "react";
import { MockData } from "./use-mock-block-props/use-mock-datastore";
type MockBlockDockInfo = {
blockEntity: Entity;
blockSchema?: Partial<EntityType>;
blockEntitySubgraph: Subgraph<SubgraphRootTypes["entity"]>;
blockInfo: {

@@ -18,3 +16,3 @@ blockType: {

};
datastore: MockData;
graph: Subgraph;
debugMode: boolean;

@@ -24,3 +22,3 @@ logs: Message[];

setDebugMode: Dispatch<SetStateAction<boolean>>;
setEntityIdOfEntityForBlock: Dispatch<SetStateAction<string>>;
setEntityEditionIdOfEntityForBlock: Dispatch<SetStateAction<EntityEditionId>>;
setLogs: Dispatch<SetStateAction<Message[]>>;

@@ -27,0 +25,0 @@ setReadonly: Dispatch<SetStateAction<boolean>>;

import { HtmlBlockDefinition } from "@blockprotocol/core";
import { Entity, EntityType, Link, LinkedAggregationDefinition } from "@blockprotocol/graph";
import { Entity, EntityEditionId } from "@blockprotocol/graph";
import { ComponentType, FunctionComponent } from "react";

@@ -16,10 +16,6 @@ type BlockDefinition = {

blockDefinition: BlockDefinition;
blockEntity?: Entity;
blockSchema?: Partial<EntityType>;
blockEntityEditionId?: EntityEditionId;
debug?: boolean;
hideDebugToggle?: boolean;
initialEntities?: Entity[];
initialEntityTypes?: EntityType[];
initialLinks?: Link[];
initialLinkedAggregations?: LinkedAggregationDefinition[];
readonly?: boolean;

@@ -43,10 +39,7 @@ blockInfo?: {

* @param props.blockDefinition the source for the block and any additional metadata required
* @param [props.blockEntity] the starting properties for the block entity
* @param [props.blockEntityEditionId] the `EntityEditionId` of the starting block entity
* @param [props.blockInfo] metadata about the block
* @param [props.blockSchema] the schema for the block entity
* @param [props.debug=false] display debugging information
* @param [props.hideDebugToggle=false] hide the ability to toggle the debug UI
* @param [props.initialEntities] the entities to include in the data store (NOT the block entity, which is always provided)
* @param [props.initialEntityTypes] the entity types to include in the data store (NOT the block's type, which is always provided)
* @param [props.initialLinks] the links to include in the data store
* @param [props.initialLinkedAggregations] The linkedAggregation DEFINITIONS to include in the data store (results will be resolved automatically)

@@ -53,0 +46,0 @@ * @param [props.readonly=false] whether the block should display in readonly mode or not

@@ -33,2 +33,3 @@ "use strict";

const block_renderer_1 = require("./block-renderer");
const get_entity_1 = require("./datastore/hook-implementations/entity/get-entity");
const hook_portals_1 = require("./hook-portals");

@@ -48,21 +49,19 @@ const mock_block_dock_context_1 = require("./mock-block-dock-context");

* @param props.blockDefinition the source for the block and any additional metadata required
* @param [props.blockEntity] the starting properties for the block entity
* @param [props.blockEntityEditionId] the `EntityEditionId` of the starting block entity
* @param [props.blockInfo] metadata about the block
* @param [props.blockSchema] the schema for the block entity
* @param [props.debug=false] display debugging information
* @param [props.hideDebugToggle=false] hide the ability to toggle the debug UI
* @param [props.initialEntities] the entities to include in the data store (NOT the block entity, which is always provided)
* @param [props.initialEntityTypes] the entity types to include in the data store (NOT the block's type, which is always provided)
* @param [props.initialLinks] the links to include in the data store
* @param [props.initialLinkedAggregations] The linkedAggregation DEFINITIONS to include in the data store (results will be resolved automatically)
* @param [props.readonly=false] whether the block should display in readonly mode or not
*/
const MockBlockDock = ({ blockDefinition, blockEntity: initialBlockEntity, blockSchema: initialBlockSchema, blockInfo, debug: initialDebug = false, hideDebugToggle = false, initialEntities, initialEntityTypes, initialLinks, initialLinkedAggregations, readonly: initialReadonly = false, }) => {
const { blockEntity, blockGraph, blockSchema, datastore, entityTypes, graphServiceCallbacks, linkedAggregations, readonly, setEntityIdOfEntityForBlock, setReadonly, } = (0, use_mock_block_props_1.useMockBlockProps)({
blockEntity: initialBlockEntity,
blockSchema: initialBlockSchema,
const MockBlockDock = ({ blockDefinition, blockEntityEditionId: initialBlockEntityEditionId, blockInfo, debug: initialDebug = false, hideDebugToggle = false, initialEntities,
// initialLinkedAggregations,
readonly: initialReadonly = false, }) => {
const { blockEntityEditionId, mockDatastore,
// linkedAggregations,
readonly, setEntityEditionIdOfEntityForBlock, setReadonly, } = (0, use_mock_block_props_1.useMockBlockProps)({
blockEntityEditionId: initialBlockEntityEditionId,
initialEntities,
initialEntityTypes,
initialLinks,
initialLinkedAggregations,
// initialLinkedAggregations,
readonly: !!initialReadonly,

@@ -73,2 +72,12 @@ });

const wrapperRef = (0, react_3.useRef)(null);
const blockEntitySubgraph = (0, get_entity_1.getEntity)({
entityId: blockEntityEditionId.baseId,
graphResolveDepths: {
hasLeftEntity: { incoming: 2, outgoing: 2 },
hasRightEntity: { incoming: 2, outgoing: 2 },
},
}, mockDatastore.graph);
if (!blockEntitySubgraph) {
throw new Error(`Failed to get subgraph for block entity`);
}
const blockType = "ReactComponent" in blockDefinition

@@ -83,14 +92,11 @@ ? "react"

graph: {
blockEntitySubgraph,
readonly,
blockEntity,
blockGraph,
entityTypes,
linkedAggregations,
// linkedAggregations,
},
};
const { graphServiceCallbacks } = mockDatastore;
const { graphService } = (0, react_1.useGraphEmbedderService)(wrapperRef, {
blockGraph,
blockEntity,
entityTypes,
linkedAggregations,
blockEntitySubgraph,
// linkedAggregations,
callbacks: graphServiceCallbacks,

@@ -165,22 +171,12 @@ readonly,

graphService,
value: blockEntity,
valueName: "blockEntity",
value: blockEntitySubgraph,
valueName: "blockEntitySubgraph",
});
// useSendGraphValue({
// graphService,
// value: linkedAggregations,
// valueName: "linkedAggregations",
// });
(0, use_send_graph_value_1.useSendGraphValue)({
graphService,
value: blockGraph,
valueName: "blockGraph",
});
(0, use_send_graph_value_1.useSendGraphValue)({
graphService,
value: entityTypes,
valueName: "entityTypes",
});
(0, use_send_graph_value_1.useSendGraphValue)({
graphService,
value: linkedAggregations,
valueName: "linkedAggregations",
});
(0, use_send_graph_value_1.useSendGraphValue)({
graphService,
value: readonly,

@@ -211,9 +207,9 @@ valueName: "readonly",

: undefined })) : null;
return ((0, jsx_runtime_1.jsxs)(mock_block_dock_context_1.MockBlockDockProvider, { blockEntity: blockEntity, blockInfo: blockInfo ?? {
return ((0, jsx_runtime_1.jsxs)(mock_block_dock_context_1.MockBlockDockProvider, { blockEntitySubgraph: blockEntitySubgraph, blockInfo: blockInfo ?? {
blockType: {
entryPoint: blockType,
},
}, blockSchema: blockSchema, datastore: datastore, debugMode: debugMode, readonly: readonly, setReadonly: setReadonly, setDebugMode: setDebugMode, setEntityIdOfEntityForBlock: setEntityIdOfEntityForBlock, updateEntity: graphServiceCallbacks.updateEntity, children: [(0, jsx_runtime_1.jsx)(hook_portals_1.HookPortals, { hooks: hooks }), (0, jsx_runtime_1.jsx)("div", { ref: wrapperRef, children: (0, jsx_runtime_1.jsx)(react_3.Suspense, { children: hideDebugToggle && !debugMode ? (blockRenderer) : ((0, jsx_runtime_1.jsx)(MockBlockDockUi, { children: blockRenderer })) }) })] }));
}, graph: mockDatastore.graph, debugMode: debugMode, readonly: readonly, setReadonly: setReadonly, setDebugMode: setDebugMode, setEntityEditionIdOfEntityForBlock: setEntityEditionIdOfEntityForBlock, updateEntity: graphServiceCallbacks.updateEntity, children: [(0, jsx_runtime_1.jsx)(hook_portals_1.HookPortals, { hooks: hooks }), (0, jsx_runtime_1.jsx)("div", { ref: wrapperRef, children: (0, jsx_runtime_1.jsx)(react_3.Suspense, { children: hideDebugToggle && !debugMode ? (blockRenderer) : ((0, jsx_runtime_1.jsx)(MockBlockDockUi, { children: blockRenderer })) }) })] }));
};
exports.MockBlockDock = MockBlockDock;
//# sourceMappingURL=mock-block-dock.js.map

@@ -1,24 +0,15 @@

import { BlockGraph, EmbedderGraphMessageCallbacks, Entity, EntityType, Link, LinkedAggregation, LinkedAggregationDefinition } from "@blockprotocol/graph";
import { Entity, EntityEditionId } from "@blockprotocol/graph";
import { Dispatch, SetStateAction } from "react";
import { MockData } from "./use-mock-block-props/use-mock-datastore";
import { MockDatastore } from "./datastore/use-mock-datastore";
export type MockBlockHookArgs = {
blockEntity?: Entity;
blockSchema?: Partial<EntityType>;
blockEntityEditionId?: EntityEditionId;
initialEntities?: Entity[];
initialEntityTypes?: EntityType[];
initialLinks?: Link[];
initialLinkedAggregations?: LinkedAggregationDefinition[];
readonly: boolean;
};
export type MockBlockHookResult = {
blockEntity: Entity;
blockGraph: BlockGraph;
blockSchema?: Partial<EntityType>;
datastore: MockData;
entityTypes: EntityType[];
graphServiceCallbacks: Required<EmbedderGraphMessageCallbacks>;
linkedAggregations: LinkedAggregation[];
blockEntityEditionId: EntityEditionId;
mockDatastore: MockDatastore;
readonly: boolean;
setReadonly: Dispatch<SetStateAction<boolean>>;
setEntityIdOfEntityForBlock: Dispatch<SetStateAction<string>>;
setEntityEditionIdOfEntityForBlock: Dispatch<SetStateAction<EntityEditionId>>;
};

@@ -29,9 +20,6 @@ /**

* See README.md for usage instructions.
* @param [blockEntity] the block's own starting properties, if any
* @param [blockSchema] - The schema for the block entity
* @param [blockEntityEditionId] the `EntityEditionId` of the block's own starting entity, if any
* @param [initialEntities] - The entities to include in the data store (NOT the block entity, which is always provided)
* @param [initialEntityTypes] - The entity types to include in the data store (NOT the block's type, which is always provided)
* @param [initialLinks] - The links to include in the data store
* @param [initialLinkedAggregations] - The linkedAggregation DEFINITIONS to include in the data store (results will be resolved automatically)
*/
export declare const useMockBlockProps: ({ blockEntity: externalBlockEntity, blockSchema: externalBlockSchema, initialEntities, initialEntityTypes, initialLinks, initialLinkedAggregations, readonly: externalReadonly, }: MockBlockHookArgs) => MockBlockHookResult;
export declare const useMockBlockProps: ({ blockEntityEditionId: externalBlockEntityEditionId, initialEntities, readonly: externalReadonly, }: MockBlockHookArgs) => MockBlockHookResult;

@@ -6,5 +6,4 @@ "use strict";

const data_1 = require("./data");
const use_mock_datastore_1 = require("./datastore/use-mock-datastore");
const use_default_state_1 = require("./use-default-state");
const use_link_fields_1 = require("./use-mock-block-props/use-link-fields");
const use_mock_datastore_1 = require("./use-mock-block-props/use-mock-datastore");
/**

@@ -14,91 +13,52 @@ * A hook to generate Block Protocol properties and callbacks for use in testing blocks.

* See README.md for usage instructions.
* @param [blockEntity] the block's own starting properties, if any
* @param [blockSchema] - The schema for the block entity
* @param [blockEntityEditionId] the `EntityEditionId` of the block's own starting entity, if any
* @param [initialEntities] - The entities to include in the data store (NOT the block entity, which is always provided)
* @param [initialEntityTypes] - The entity types to include in the data store (NOT the block's type, which is always provided)
* @param [initialLinks] - The links to include in the data store
* @param [initialLinkedAggregations] - The linkedAggregation DEFINITIONS to include in the data store (results will be resolved automatically)
*/
const useMockBlockProps = ({ blockEntity: externalBlockEntity, blockSchema: externalBlockSchema, initialEntities, initialEntityTypes, initialLinks, initialLinkedAggregations, readonly: externalReadonly, }) => {
const [entityIdOfEntityForBlock, setEntityIdOfEntityForBlock] = (0, use_default_state_1.useDefaultState)(externalBlockEntity?.entityId ?? "");
const useMockBlockProps = ({ blockEntityEditionId: externalBlockEntityEditionId, initialEntities,
// initialLinkedAggregations,
readonly: externalReadonly, }) => {
const [entityEditionIdOfEntityForBlock, setEntityEditionIdOfEntityForBlock] = (0, use_default_state_1.useDefaultState)(externalBlockEntityEditionId ?? {
baseId: "",
versionId: new Date().toISOString(),
});
const [readonly, setReadonly] = (0, use_default_state_1.useDefaultState)(externalReadonly);
const { initialBlockEntity, mockData } = (0, react_1.useMemo)(() => {
const entityTypeId = externalBlockEntity?.entityTypeId ?? "block-type-1";
const blockEntityType = {
entityTypeId,
schema: {
title: "BlockType",
type: "object",
$schema: "https://json-schema.org/draft/2019-09/schema",
$id: "http://localhost/blockType1",
...(externalBlockSchema ?? {}),
},
const { mockData } = (0, react_1.useMemo)(() => {
const nextMockData = {
entities: [...(initialEntities ?? data_1.mockData.entities)],
// linkedAggregationDefinitions:
// initialLinkedAggregations ??
// initialMockData.linkedAggregationDefinitions,
};
const newBlockEntity = {
entityId: "block1",
entityTypeId,
properties: {},
};
if (externalBlockEntity && Object.keys(externalBlockEntity).length > 0) {
Object.assign(newBlockEntity, externalBlockEntity);
if (nextMockData.entities.length === 0) {
throw new Error(`Mock data didn't contain any entities, it has to at least contain the block entity`);
}
const nextMockData = {
entities: [
newBlockEntity,
...(initialEntities ?? data_1.mockData.entities),
],
entityTypes: [
blockEntityType,
...(initialEntityTypes ?? data_1.mockData.entityTypes),
],
links: initialLinks ?? data_1.mockData.links,
linkedAggregationDefinitions: initialLinkedAggregations ??
data_1.mockData.linkedAggregationDefinitions,
};
return { initialBlockEntity: newBlockEntity, mockData: nextMockData };
let blockEntity;
if (externalBlockEntityEditionId) {
blockEntity = nextMockData.entities.find((entity) => entity.metadata.editionId.baseId ===
externalBlockEntityEditionId.baseId &&
entity.metadata.editionId.versionId ===
externalBlockEntityEditionId.versionId);
if (blockEntity === undefined) {
throw new Error(`Mock data didn't contain the given block entity edition ID: ${JSON.stringify(externalBlockEntityEditionId)}`);
}
}
else {
blockEntity = nextMockData.entities[0];
setEntityEditionIdOfEntityForBlock(blockEntity.metadata.editionId);
}
return { mockData: nextMockData };
}, [
externalBlockEntity,
externalBlockSchema,
externalBlockEntityEditionId,
initialEntities,
initialEntityTypes,
initialLinks,
initialLinkedAggregations,
setEntityEditionIdOfEntityForBlock,
// initialLinkedAggregations,
]);
const datastore = (0, use_mock_datastore_1.useMockDatastore)(mockData, readonly);
const { entities, entityTypes, graphServiceCallbacks, links, linkedAggregationDefinitions, } = datastore;
const latestBlockEntity = (0, react_1.useMemo)(() => {
return (entities.find((entity) => entity.entityId === entityIdOfEntityForBlock) ??
// fallback in case the entityId of the wrapped component is updated by updating its props
mockData.entities.find((entity) => entity.entityId === initialBlockEntity.entityId));
}, [
entities,
initialBlockEntity.entityId,
mockData.entities,
entityIdOfEntityForBlock,
]);
if (!latestBlockEntity) {
throw new Error("Cannot find block entity. Did it delete itself?");
}
// construct BP-specified link fields from the links and linkedAggregations in the datastore
const { blockGraph, linkedAggregations } = (0, use_link_fields_1.useLinkFields)({
entities,
links,
linkedAggregationDefinitions,
startingEntity: latestBlockEntity,
});
// @todo we don't do anything with this type except check it exists - do we need to do this?
const latestBlockEntityType = (0, react_1.useMemo)(() => entityTypes.find((entityType) => entityType.entityTypeId === latestBlockEntity.entityTypeId), [entityTypes, latestBlockEntity.entityTypeId]);
if (!latestBlockEntityType) {
throw new Error("Cannot find block entity type. Has it been deleted?");
}
const mockDatastore = (0, use_mock_datastore_1.useMockDatastore)(mockData, readonly);
return {
blockEntity: latestBlockEntity,
blockGraph,
blockSchema: externalBlockSchema,
datastore,
entityTypes,
graphServiceCallbacks,
linkedAggregations,
blockEntityEditionId: entityEditionIdOfEntityForBlock,
mockDatastore,
// linkedAggregations,
readonly,
setEntityIdOfEntityForBlock,
setEntityEditionIdOfEntityForBlock,
setReadonly,

@@ -105,0 +65,0 @@ };

@@ -1,6 +0,18 @@

import { AggregateEntitiesData, AggregateEntitiesResult, AggregateEntityTypesData, Entity, EntityType } from "@blockprotocol/graph";
import { AggregateEntitiesData, AggregateEntitiesResult, AggregateEntityTypesData, AggregateEntityTypesResult, Entity, EntityType, Subgraph, SubgraphRootTypes } from "@blockprotocol/graph";
type TupleEntry<T extends readonly unknown[], I extends unknown[] = [], R = never> = T extends readonly [infer Head, ...infer Tail] ? TupleEntry<Tail, [...I, unknown], R | [`${I["length"]}`, Head]> : R;
type ObjectEntry<T extends {}> = T extends object ? {
[K in keyof T]: [K, Required<T>[K]];
}[keyof T] extends infer E ? E extends [infer K, infer V] ? K extends string | number ? [`${K}`, V] : never : never : never : never;
export type Entry<T extends {}> = T extends readonly [unknown, ...unknown[]] ? TupleEntry<T> : T extends ReadonlyArray<infer U> ? [`${number}`, U] : ObjectEntry<T>;
/** `Object.entries` analogue which returns a well-typed array */
export declare function typedEntries<T extends {}>(object: T): ReadonlyArray<Entry<T>>;
export declare const get: (obj: unknown, path: string | string[], defaultValue?: undefined) => unknown;
export declare const set: (obj: {}, path: string | string[], value: unknown) => void;
export declare const debounce: <T extends (...args: any[]) => any>(func: T, delayMs: number) => (...args: Parameters<T>) => void;
export declare function filterAndSortEntitiesOrTypes(entities: Entity[], payload: AggregateEntitiesData): AggregateEntitiesResult<Entity>;
export declare function filterAndSortEntitiesOrTypes(entities: EntityType[], payload: AggregateEntityTypesData): AggregateEntitiesResult<EntityType>;
export type FilterResult<T extends Entity | EntityType = Entity | EntityType> = {
results: T[];
operation: AggregateEntitiesResult<Subgraph<SubgraphRootTypes["entity"]>>["operation"] | AggregateEntityTypesResult<Subgraph<SubgraphRootTypes["entityType"]>>["operation"];
};
export declare function filterAndSortEntitiesOrTypes(entities: Entity[], payload: AggregateEntitiesData): FilterResult<Entity>;
export declare function filterAndSortEntitiesOrTypes(entities: EntityType[], payload: AggregateEntityTypesData): FilterResult<EntityType>;
export {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.filterAndSortEntitiesOrTypes = exports.debounce = exports.set = exports.get = void 0;
exports.filterAndSortEntitiesOrTypes = exports.debounce = exports.set = exports.get = exports.typedEntries = void 0;
/** `Object.entries` analogue which returns a well-typed array */
function typedEntries(object) {
return Object.entries(object);
}
exports.typedEntries = typedEntries;
// Saves us from using heavy lodash dependency

@@ -48,3 +53,3 @@ // Source: https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_get

return entities.filter((entity) => {
if (entityTypeId && entityTypeId !== entity.entityTypeId) {
if (entityTypeId && entityTypeId !== entity.metadata.entityTypeId) {
return false;

@@ -147,3 +152,3 @@ }

if (entityTypeIdFilter) {
results = results.filter((entity) => entity.entityTypeId === entityTypeIdFilter);
results = results.filter((entity) => entity.metadata.entityTypeId === entityTypeIdFilter);
}

@@ -150,0 +155,0 @@ const totalCount = results.length;

@@ -1,1 +0,1 @@

export declare const MOCK_BLOCK_DOCK_VERSION = "0.0.39";
export declare const MOCK_BLOCK_DOCK_VERSION = "0.1.0";
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MOCK_BLOCK_DOCK_VERSION = void 0;
exports.MOCK_BLOCK_DOCK_VERSION = "0.0.39";
exports.MOCK_BLOCK_DOCK_VERSION = "0.1.0";
//# sourceMappingURL=version.js.map
import { Entity } from "@blockprotocol/graph";
declare const entities: Entity[];
declare const entities: Entity<Record<string, import("@blockprotocol/graph").EntityPropertyValue>>[];
export { entities };

@@ -0,17 +1,20 @@

import { extractBaseUri } from "@blockprotocol/type-system/slim";
import { entityTypes } from "./entity-types";
import { propertyTypes } from "./property-types";
import { companyNames, personNames } from "./words";
const entities = [];
const NUMBER_OF_ENTITIES_TO_CREATE = Math.min(personNames.length, companyNames.length);
const createPerson = (entityId) => {
const now = new Date();
const name = personNames[entityId] ?? "Unknown Person";
return {
entityId: `person-${entityId.toString()}`,
entityTypeId: "Person",
metadata: {
editionId: {
baseId: `person-${entityId.toString()}`,
versionId: new Date().toISOString(),
},
entityTypeId: entityTypes.person.$id,
},
properties: {
createdAt: now,
updatedAt: now,
age: Math.ceil(Math.random() * 100),
email: `${name}@example.com`,
name,
username: name.toLowerCase(),
[extractBaseUri(propertyTypes.age.$id)]: Math.ceil(Math.random() * 100),
[extractBaseUri(propertyTypes.email.$id)]: `${name}@example.com`,
[extractBaseUri(propertyTypes.name.$id)]: name,
[extractBaseUri(propertyTypes.username.$id)]: name.toLowerCase(),
},

@@ -21,20 +24,77 @@ };

const createCompany = (entityId) => {
const now = new Date();
const name = companyNames[entityId];
const name = companyNames[entityId] ?? "Unknown Company";
return {
entityId: `company-${entityId.toString()}`,
entityTypeId: "Company",
metadata: {
editionId: {
baseId: `company-${entityId.toString()}`,
versionId: new Date().toISOString(),
},
entityTypeId: entityTypes.company.$id,
},
properties: {
createdAt: now,
updatedAt: now,
employees: Math.ceil(Math.random() * 10000),
name,
[extractBaseUri(propertyTypes.numberOfEmployees.$id)]: Math.ceil(Math.random() * 10000),
[extractBaseUri(propertyTypes.name.$id)]: name,
},
};
};
for (let id = 0; id < NUMBER_OF_ENTITIES_TO_CREATE; id++) {
entities.push(createCompany(id));
entities.push(createPerson(id));
}
const createWorksForLink = (sourceEntityId, destinationEntityId) => {
return {
metadata: {
editionId: {
baseId: `${sourceEntityId}-works-for-${destinationEntityId}`,
versionId: new Date().toISOString(),
},
entityTypeId: entityTypes.worksFor.$id,
},
properties: {},
linkData: {
leftEntityId: sourceEntityId,
rightEntityId: destinationEntityId,
},
};
};
const createFounderOfLink = (sourceEntityId, destinationEntityId) => {
return {
metadata: {
editionId: {
baseId: `${sourceEntityId}-founder-of-${destinationEntityId}`,
versionId: new Date().toISOString(),
},
entityTypeId: entityTypes.founderOf.$id,
},
properties: {},
linkData: {
leftEntityId: sourceEntityId,
rightEntityId: destinationEntityId,
},
};
};
const createEntities = () => {
// First create people and companies in separate lists
const people = [];
const companies = [];
for (let idx = 0; idx < personNames.length; idx++) {
people.push(createPerson(idx));
}
for (let idx = 0; idx < companyNames.length; idx++) {
companies.push(createCompany(idx));
}
const entities = [];
// For each company, `pop` (to avoid double selection in the next step) a person to be the founder, and start building
// the final entities list
for (const company of companies) {
const founder = people.pop();
if (founder) {
entities.push(createFounderOfLink(founder.metadata.editionId.baseId, company.metadata.editionId.baseId));
entities.push(founder);
}
}
for (const person of people) {
entities.push(createWorksForLink(person.metadata.editionId.baseId, companies[Math.floor(Math.random() * companies.length)].metadata
.editionId.baseId));
}
return [...entities, ...people, ...companies];
};
const entities = createEntities();
export { entities };
//# sourceMappingURL=entities.js.map
import { EntityType } from "@blockprotocol/graph";
export declare const entityTypes: EntityType[];
export declare const entityTypes: {
company: EntityType;
person: EntityType;
worksFor: EntityType;
founderOf: EntityType;
testType: EntityType;
};

@@ -1,58 +0,116 @@

export const entityTypes = [
{
entityTypeId: "Company",
schema: {
$id: "https://example.com/types/Company",
title: "Company",
type: "object",
$schema: "https://json-schema.org/draft/2019-09/schema",
description: "A company or organisation.",
properties: {
employees: {
type: "number",
description: "The number of employees in the company.",
},
name: {
type: "string",
description: "A display name for the company.",
},
},
labelProperty: "name",
required: ["name", "employees"],
import { extractBaseUri } from "@blockprotocol/type-system/slim";
import { propertyTypes } from "./property-types";
const worksFor = {
kind: "entityType",
$id: "https://example.com/types/entity-type/works-for/v/1",
type: "object",
title: "Works For",
description: "Has employment at this entity.",
allOf: [
{
$ref: "https://blockprotocol.org/@blockprotocol/types/entity-type/link/v/1",
},
],
properties: {},
required: [],
};
const founderOf = {
kind: "entityType",
$id: "https://example.com/types/entity-type/founder-of/v/1",
type: "object",
title: "Founder of",
description: "Established this entity.",
allOf: [
{
$ref: "https://blockprotocol.org/@blockprotocol/types/entity-type/link/v/1",
},
],
properties: {},
required: [],
};
const company = {
kind: "entityType",
$id: "https://example.com/types/entity-type/company/v/1",
type: "object",
title: "Company",
description: "A company or organization.",
properties: {
[extractBaseUri(propertyTypes.numberOfEmployees.$id)]: {
$ref: propertyTypes.numberOfEmployees.$id,
},
[extractBaseUri(propertyTypes.name.$id)]: {
$ref: propertyTypes.name.$id,
},
},
{
entityTypeId: "Person",
schema: {
$id: "https://example.com/types/Person",
title: "Person",
type: "object",
$schema: "https://json-schema.org/draft/2019-09/schema",
description: "A human person.",
properties: {
age: {
type: "number",
description: "The age of the person, in years.",
},
email: {
type: "string",
description: "An email address.",
format: "email",
},
name: {
type: "string",
description: "The person's name.",
},
username: {
description: "The person's username in this application",
type: "string",
minLength: 4,
maxLength: 24,
},
required: [
extractBaseUri(propertyTypes.numberOfEmployees.$id),
extractBaseUri(propertyTypes.name.$id),
],
links: {},
};
const person = {
kind: "entityType",
$id: "https://example.com/types/entity-type/person/v/1",
type: "object",
title: "Person",
description: "A human person.",
properties: {
[extractBaseUri(propertyTypes.age.$id)]: {
$ref: propertyTypes.age.$id,
},
[extractBaseUri(propertyTypes.email.$id)]: {
$ref: propertyTypes.email.$id,
},
[extractBaseUri(propertyTypes.name.$id)]: {
$ref: propertyTypes.name.$id,
},
[extractBaseUri(propertyTypes.username.$id)]: {
$ref: propertyTypes.username.$id,
},
},
required: [
extractBaseUri(propertyTypes.age.$id),
extractBaseUri(propertyTypes.email.$id),
extractBaseUri(propertyTypes.name.$id),
extractBaseUri(propertyTypes.username.$id),
],
links: {
[worksFor.$id]: {
type: "array",
items: {
$ref: company.$id,
},
labelProperty: "name",
required: ["age", "email", "name", "username"],
ordered: false,
},
[founderOf.$id]: {
type: "array",
items: {
$ref: company.$id,
},
ordered: false,
},
},
];
};
const testType = {
kind: "entityType",
$id: "https://example.com/types/entity-type/test-type/v/1",
type: "object",
title: "Test Type",
description: "A Type for Testing",
properties: {
[extractBaseUri(propertyTypes.name.$id)]: {
$ref: propertyTypes.name.$id,
},
},
required: [extractBaseUri(propertyTypes.name.$id)],
links: {},
};
export const entityTypes = {
company,
person,
worksFor,
founderOf,
testType,
};
// satisfies Record<string, EntityType> };
//# sourceMappingURL=entity-types.js.map

@@ -1,2 +0,2 @@

import { MockData } from "../use-mock-block-props/use-mock-datastore";
import { MockData } from "../datastore/use-mock-datastore";
export declare const mockData: MockData;
import { entities } from "./entities";
import { entityTypes } from "./entity-types";
import { linkedAggregationDefinitions } from "./linked-aggregation-definitions";
import { links } from "./links";
export const mockData = {
entities,
entityTypes,
links,
linkedAggregationDefinitions,
// linkedAggregationDefinitions,
};
//# sourceMappingURL=index.js.map

@@ -15,2 +15,6 @@ export const personNames = [

"Louis",
"Alice",
"Johanna",
"Jeremy",
"Samuel",
];

@@ -17,0 +21,0 @@ export const companyNames = [

/// <reference types="react" />
export declare const BlockSchemaView: () => JSX.Element | null;
import { EntityType } from "@blockprotocol/graph";
export declare const BlockSchemaView: ({ entityType }: {
entityType: EntityType;
}) => JSX.Element;
import { jsx as _jsx } from "react/jsx-runtime";
import { Box } from "@mui/material";
import { useMockBlockDockContext } from "../../mock-block-dock-context";
import { JsonView } from "./json-view";
export const BlockSchemaView = () => {
const { blockSchema } = useMockBlockDockContext();
if (!blockSchema) {
return null;
}
return (_jsx(Box, { maxWidth: 800, children: _jsx(JsonView, { collapseKeys: Object.keys(blockSchema), rootName: "blockSchema", src: blockSchema }) }));
export const BlockSchemaView = ({ entityType }) => {
return (_jsx(Box, { maxWidth: 800, children: _jsx(JsonView, { collapseKeys: Object.keys(entityType), rootName: "blockSchema", src: entityType }) }));
};
//# sourceMappingURL=block-schema-view.js.map
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { Box } from "@mui/material";
import { useMockBlockDockContext } from "../../mock-block-dock-context";
import { DatastoreGraphVisualisation } from "./datastore-graph-visualisation";
import { DatastoreGraphVisualization } from "./datastore-graph-visualization";
import { JsonView } from "./json-view";
export const DataStoreView = () => {
const { datastore } = useMockBlockDockContext();
const { graph } = useMockBlockDockContext();
return (_jsxs(Box, { sx: {

@@ -15,14 +15,7 @@ minHeight: "100%",

},
}, children: [_jsx(JsonView, { collapseKeys: [
"entities",
"entityTypes",
"links",
"linkedAggregations",
], rootName: "datastore", src: {
entities: datastore.entities,
entityTypes: datastore.entityTypes,
links: datastore.links,
linkedAggregations: datastore.linkedAggregationDefinitions,
} }), _jsx(DatastoreGraphVisualisation, {})] }));
}, children: [_jsx(JsonView, { collapseKeys: ["vertices", "edges"], rootName: "datastore", src: {
vertices: graph.vertices,
edges: graph.edges,
} }), _jsx(DatastoreGraphVisualization, {})] }));
};
//# sourceMappingURL=datastore-view.js.map
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { getEntities, getEntity, getEntityTypes, getRoots, } from "@blockprotocol/graph/stdlib";
import { Box, Button, MenuItem, Popover, Select, Typography, } from "@mui/material";
import { useState } from "react";
import { useMemo, useState } from "react";
import { useMockBlockDockContext } from "../../mock-block-dock-context";

@@ -14,6 +15,7 @@ import { JsonView } from "./json-view";

const [anchorEl, setAnchorEl] = useState(null);
const { blockEntity, setEntityIdOfEntityForBlock, datastore } = useMockBlockDockContext();
const [entityTypeId, setEntityTypeId] = useState(blockEntity.entityTypeId);
const [entityId, setEntityIdOfProposedEntityForBlock] = useState(blockEntity.entityId);
const selectedEntity = datastore.entities.find((entity) => entity.entityId === entityId && entity.entityTypeId === entityTypeId);
const { blockEntitySubgraph, setEntityEditionIdOfEntityForBlock, graph } = useMockBlockDockContext();
const blockEntity = useMemo(() => getRoots(blockEntitySubgraph)[0], [blockEntitySubgraph]);
const [entityTypeId, setEntityTypeId] = useState(blockEntity.metadata.entityTypeId);
const [entityId, setEntityIdOfProposedEntityForBlock] = useState(blockEntity.metadata.editionId.baseId);
const selectedEntity = useMemo(() => (entityId ? getEntity(graph, entityId) : blockEntity), [graph, blockEntity, entityId]);
const handleClick = (event) => {

@@ -27,3 +29,3 @@ setAnchorEl(event.currentTarget);

if (selectedEntity) {
setEntityIdOfEntityForBlock(selectedEntity.entityId);
setEntityEditionIdOfEntityForBlock(selectedEntity.metadata.editionId);
}

@@ -48,9 +50,9 @@ closePopover();

setEntityTypeId(event.target.value);
}, sx: { mb: 2 }, fullWidth: true, children: datastore.entityTypes.map((type) => (_jsx(MenuItem, { value: type.entityTypeId, children: type.entityTypeId }, type.entityTypeId))) })] }), _jsxs(Box, { children: [_jsx(Typography, { component: "label", htmlFor: "entity-id-selector", fontWeight: 500, variant: "caption", children: "Entity Id" }), _jsx(Select, { id: "entity-id-selector", size: "small", value: entityId, placeholder: "Select Entity", onChange: (event) => {
}, sx: { mb: 2 }, fullWidth: true, children: getEntityTypes(graph).map(({ schema: entityType }) => (_jsx(MenuItem, { value: entityType.$id, children: entityType.$id }, entityType.$id))) })] }), _jsxs(Box, { children: [_jsx(Typography, { component: "label", htmlFor: "entity-id-selector", fontWeight: 500, variant: "caption", children: "Entity Id" }), _jsx(Select, { id: "entity-id-selector", size: "small", value: entityId, placeholder: "Select Entity", onChange: (event) => {
setEntityIdOfProposedEntityForBlock(event.target.value);
}, sx: {
mb: 2,
}, fullWidth: true, children: datastore.entities
.filter((entity) => entity.entityTypeId === entityTypeId)
.map((entity) => (_jsx(MenuItem, { value: entity.entityId, children: entity.entityId }, entity.entityId))) })] }), _jsx(Button, { variant: "contained", disableFocusRipple: true, disableRipple: true, sx: { textTransform: "none" }, onClick: handleSubmit, children: "Switch Entity" })] }), _jsx(Box, { sx: {
}, fullWidth: true, children: getEntities(graph)
.filter((entity) => entity.metadata.entityTypeId === entityTypeId)
.map((entity) => (_jsx(MenuItem, { value: entity.metadata.editionId.baseId, children: entity.metadata.editionId.baseId }, entity.metadata.editionId.baseId))) })] }), _jsx(Button, { variant: "contained", disableFocusRipple: true, disableRipple: true, sx: { textTransform: "none" }, onClick: handleSubmit, children: "Switch Entity" })] }), _jsx(Box, { sx: {
".react-json-view": {

@@ -61,4 +63,4 @@ height: 250,

},
}, children: _jsx(JsonView, { rootName: "properties", collapseKeys: [], src: selectedEntity?.properties ?? {}, enableClipboard: false, quotesOnKeys: false, displayObjectSize: false, displayDataTypes: false }) })] })] }));
}, children: _jsx(JsonView, { rootName: "properties", collapseKeys: [], src: blockEntity?.properties ?? {}, enableClipboard: false, quotesOnKeys: false, displayObjectSize: false, displayDataTypes: false }) })] })] }));
};
//# sourceMappingURL=entity-switcher.js.map
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { getEntityTypeById, getRoots } from "@blockprotocol/graph/stdlib";
import { Box, Collapse, Container, Grid, Switch, Typography, } from "@mui/material";
import Ajv from "ajv";
import { useMemo } from "react";
import { useMockBlockDockContext } from "../../mock-block-dock-context";

@@ -9,41 +10,63 @@ import { customColors } from "../theme/palette";

import { JsonView } from "./json-view";
const ajv = new Ajv();
// const ajv = new Ajv();
export const PropertiesView = () => {
const { readonly, setReadonly, blockSchema, blockEntity, updateEntity } = useMockBlockDockContext();
const validate = ajv.compile(blockSchema ?? {});
validate(blockEntity.properties);
const errors = validate.errors?.map((error) => error.message);
const { readonly, setReadonly, blockEntitySubgraph, updateEntity, graph } = useMockBlockDockContext();
const blockEntity = useMemo(() => getRoots(blockEntitySubgraph)[0], [blockEntitySubgraph]);
const blockEntityType = useMemo(() => getEntityTypeById(graph, blockEntity.metadata.entityTypeId), [graph, blockEntity]);
/** @todo - reimplement validation */
// const validate = ajv.compile(blockSchema ?? {});
// validate(blockEntity.properties);
// const errors = validate.errors?.map((error) => error.message);
const errors = [];
return (_jsx(Container, { maxWidth: "xl", children: _jsxs(Grid, { container: true, children: [_jsx(Grid, { item: true, xs: 6, children: _jsxs(Box, { mb: 3, children: [_jsxs(Box, { sx: { display: "flex", justifyContent: "space-between", mb: 1 }, children: [_jsx(Typography, { variant: "subtitle2", children: "Entity Properties" }), _jsx(EntitySwitcher, {}), _jsxs(Box, { sx: { display: "flex" }, children: [_jsx(Typography, { variant: "subtitle2", mr: 1, children: "Read-only mode" }), _jsx(Switch, { checked: readonly, onChange: (evt) => setReadonly(evt.target.checked), size: "small" })] })] }), _jsxs(Box, { maxWidth: 800, children: [_jsx(JsonView, { collapseKeys: ["graph"], rootName: "blockEntity", sortKeys: true, src: blockEntity ?? {}, onEdit: (args) => {
// These fields should not be edited
if (args.name &&
["entityType", "entityTypeId", "entityId"].includes(args.name)) {
(args.name.includes("versionId") ||
args.name.includes("baseId") ||
args.name.includes("leftEntityId") ||
args.name.includes("rightEntityId"))) {
return false;
}
const entity = args.updated_src;
void updateEntity({
data: args.updated_src,
data: {
entityId: entity.metadata.editionId.baseId,
entityTypeId: entity.metadata.entityTypeId,
properties: entity.properties,
leftToRightOrder: entity.linkData?.leftToRightOrder,
rightToLeftOrder: entity.linkData?.rightToLeftOrder,
},
});
}, onAdd: (args) => {
// don't allow adding of top level fields
if (args.name && !args.name.includes("properties")) {
if (!args.namespace.includes("properties")) {
return false;
}
const entity = args.updated_src;
void updateEntity({
data: args.updated_src,
data: {
entityId: entity.metadata.editionId.baseId,
entityTypeId: entity.metadata.entityTypeId,
properties: entity.properties,
leftToRightOrder: entity.linkData?.leftToRightOrder,
rightToLeftOrder: entity.linkData?.rightToLeftOrder,
},
});
}, onDelete: (args) => {
// These fields should not be deleted
if (args.name &&
[
"entityType",
"entityTypeId",
"entityId",
"properties",
].includes(args.name)) {
// don't allow deleting of top level fields
if (!args.namespace.includes("properties")) {
return false;
}
const entity = args.updated_src;
void updateEntity({
data: args.updated_src,
data: {
entityId: entity.metadata.editionId.baseId,
entityTypeId: entity.metadata.entityTypeId,
properties: entity.properties,
leftToRightOrder: entity.linkData?.leftToRightOrder,
rightToLeftOrder: entity.linkData?.rightToLeftOrder,
},
});
}, validationMessage: "You may only edit the properties object" }), _jsx(Collapse, { in: !!errors?.length, children: errors?.map((error) => (_jsx(Typography, { variant: "subtitle2", color: customColors.red[600], children: error }, error))) })] })] }) }), _jsx(Grid, { item: true, xs: 6, children: blockSchema && (_jsxs(Box, { children: [_jsx(Typography, { variant: "subtitle2", mb: 1, children: "Block Schema" }), _jsx(BlockSchemaView, {})] })) })] }) }));
}, validationMessage: "You may only edit the properties object" }), _jsx(Collapse, { in: !!errors?.length, children: errors?.map((error) => (_jsx(Typography, { variant: "subtitle2", color: customColors.red[600], children: error }, error))) })] })] }) }), _jsx(Grid, { item: true, xs: 6, children: blockEntityType && (_jsxs(Box, { children: [_jsx(Typography, { variant: "subtitle2", mb: 1, children: "Block Schema" }), _jsx(BlockSchemaView, { entityType: blockEntityType.schema })] })) })] }) }));
};
//# sourceMappingURL=properties.js.map
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
import { getEntity } from "@blockprotocol/graph/stdlib";
import { useCallback, useMemo } from "react";

@@ -8,5 +9,5 @@ import { createPortal } from "react-dom";

const HookPortal = ({ entityId, path, type }) => {
const { datastore, readonly, updateEntity } = useMockBlockDockContext();
const { graph, readonly, updateEntity } = useMockBlockDockContext();
const { entity, value } = useMemo(() => {
const foundEntity = datastore.entities.find((currentEntity) => currentEntity.entityId === entityId);
const foundEntity = getEntity(graph, entityId);
if (!foundEntity) {

@@ -18,3 +19,3 @@ throw new Error(`Could not find entity requested by hook with entityId '${entityId}' in datastore.`);

return { entity: foundEntity, value: foundValue };
}, [datastore.entities, entityId, path]);
}, [graph, entityId, path]);
const updateValue = useCallback(async (newValue) => {

@@ -24,3 +25,9 @@ const newProperties = { ...entity?.properties };

return updateEntity({
data: { entityId, properties: newProperties },
data: {
entityId,
entityTypeId: entity.metadata.entityTypeId,
properties: newProperties,
leftToRightOrder: entity.linkData?.leftToRightOrder,
rightToLeftOrder: entity.linkData?.rightToLeftOrder,
},
});

@@ -27,0 +34,0 @@ }, [entity, entityId, path, updateEntity]);

import { Message } from "@blockprotocol/core";
import { EmbedderGraphMessageCallbacks, Entity, EntityType } from "@blockprotocol/graph";
import { EmbedderGraphMessageCallbacks, EntityEditionId, Subgraph, SubgraphRootTypes } from "@blockprotocol/graph";
import { Dispatch, ReactNode, SetStateAction } from "react";
import { MockData } from "./use-mock-block-props/use-mock-datastore";
type MockBlockDockInfo = {
blockEntity: Entity;
blockSchema?: Partial<EntityType>;
blockEntitySubgraph: Subgraph<SubgraphRootTypes["entity"]>;
blockInfo: {

@@ -18,3 +16,3 @@ blockType: {

};
datastore: MockData;
graph: Subgraph;
debugMode: boolean;

@@ -24,3 +22,3 @@ logs: Message[];

setDebugMode: Dispatch<SetStateAction<boolean>>;
setEntityIdOfEntityForBlock: Dispatch<SetStateAction<string>>;
setEntityEditionIdOfEntityForBlock: Dispatch<SetStateAction<EntityEditionId>>;
setLogs: Dispatch<SetStateAction<Message[]>>;

@@ -27,0 +25,0 @@ setReadonly: Dispatch<SetStateAction<boolean>>;

import { HtmlBlockDefinition } from "@blockprotocol/core";
import { Entity, EntityType, Link, LinkedAggregationDefinition } from "@blockprotocol/graph";
import { Entity, EntityEditionId } from "@blockprotocol/graph";
import { ComponentType, FunctionComponent } from "react";

@@ -16,10 +16,6 @@ type BlockDefinition = {

blockDefinition: BlockDefinition;
blockEntity?: Entity;
blockSchema?: Partial<EntityType>;
blockEntityEditionId?: EntityEditionId;
debug?: boolean;
hideDebugToggle?: boolean;
initialEntities?: Entity[];
initialEntityTypes?: EntityType[];
initialLinks?: Link[];
initialLinkedAggregations?: LinkedAggregationDefinition[];
readonly?: boolean;

@@ -43,10 +39,7 @@ blockInfo?: {

* @param props.blockDefinition the source for the block and any additional metadata required
* @param [props.blockEntity] the starting properties for the block entity
* @param [props.blockEntityEditionId] the `EntityEditionId` of the starting block entity
* @param [props.blockInfo] metadata about the block
* @param [props.blockSchema] the schema for the block entity
* @param [props.debug=false] display debugging information
* @param [props.hideDebugToggle=false] hide the ability to toggle the debug UI
* @param [props.initialEntities] the entities to include in the data store (NOT the block entity, which is always provided)
* @param [props.initialEntityTypes] the entity types to include in the data store (NOT the block's type, which is always provided)
* @param [props.initialLinks] the links to include in the data store
* @param [props.initialLinkedAggregations] The linkedAggregation DEFINITIONS to include in the data store (results will be resolved automatically)

@@ -53,0 +46,0 @@ * @param [props.readonly=false] whether the block should display in readonly mode or not

@@ -7,2 +7,3 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";

import { BlockRenderer } from "./block-renderer";
import { getEntity } from "./datastore/hook-implementations/entity/get-entity";
import { HookPortals } from "./hook-portals";

@@ -22,21 +23,19 @@ import { MockBlockDockProvider } from "./mock-block-dock-context";

* @param props.blockDefinition the source for the block and any additional metadata required
* @param [props.blockEntity] the starting properties for the block entity
* @param [props.blockEntityEditionId] the `EntityEditionId` of the starting block entity
* @param [props.blockInfo] metadata about the block
* @param [props.blockSchema] the schema for the block entity
* @param [props.debug=false] display debugging information
* @param [props.hideDebugToggle=false] hide the ability to toggle the debug UI
* @param [props.initialEntities] the entities to include in the data store (NOT the block entity, which is always provided)
* @param [props.initialEntityTypes] the entity types to include in the data store (NOT the block's type, which is always provided)
* @param [props.initialLinks] the links to include in the data store
* @param [props.initialLinkedAggregations] The linkedAggregation DEFINITIONS to include in the data store (results will be resolved automatically)
* @param [props.readonly=false] whether the block should display in readonly mode or not
*/
export const MockBlockDock = ({ blockDefinition, blockEntity: initialBlockEntity, blockSchema: initialBlockSchema, blockInfo, debug: initialDebug = false, hideDebugToggle = false, initialEntities, initialEntityTypes, initialLinks, initialLinkedAggregations, readonly: initialReadonly = false, }) => {
const { blockEntity, blockGraph, blockSchema, datastore, entityTypes, graphServiceCallbacks, linkedAggregations, readonly, setEntityIdOfEntityForBlock, setReadonly, } = useMockBlockProps({
blockEntity: initialBlockEntity,
blockSchema: initialBlockSchema,
export const MockBlockDock = ({ blockDefinition, blockEntityEditionId: initialBlockEntityEditionId, blockInfo, debug: initialDebug = false, hideDebugToggle = false, initialEntities,
// initialLinkedAggregations,
readonly: initialReadonly = false, }) => {
const { blockEntityEditionId, mockDatastore,
// linkedAggregations,
readonly, setEntityEditionIdOfEntityForBlock, setReadonly, } = useMockBlockProps({
blockEntityEditionId: initialBlockEntityEditionId,
initialEntities,
initialEntityTypes,
initialLinks,
initialLinkedAggregations,
// initialLinkedAggregations,
readonly: !!initialReadonly,

@@ -47,2 +46,12 @@ });

const wrapperRef = useRef(null);
const blockEntitySubgraph = getEntity({
entityId: blockEntityEditionId.baseId,
graphResolveDepths: {
hasLeftEntity: { incoming: 2, outgoing: 2 },
hasRightEntity: { incoming: 2, outgoing: 2 },
},
}, mockDatastore.graph);
if (!blockEntitySubgraph) {
throw new Error(`Failed to get subgraph for block entity`);
}
const blockType = "ReactComponent" in blockDefinition

@@ -57,14 +66,11 @@ ? "react"

graph: {
blockEntitySubgraph,
readonly,
blockEntity,
blockGraph,
entityTypes,
linkedAggregations,
// linkedAggregations,
},
};
const { graphServiceCallbacks } = mockDatastore;
const { graphService } = useGraphEmbedderService(wrapperRef, {
blockGraph,
blockEntity,
entityTypes,
linkedAggregations,
blockEntitySubgraph,
// linkedAggregations,
callbacks: graphServiceCallbacks,

@@ -139,22 +145,12 @@ readonly,

graphService,
value: blockEntity,
valueName: "blockEntity",
value: blockEntitySubgraph,
valueName: "blockEntitySubgraph",
});
// useSendGraphValue({
// graphService,
// value: linkedAggregations,
// valueName: "linkedAggregations",
// });
useSendGraphValue({
graphService,
value: blockGraph,
valueName: "blockGraph",
});
useSendGraphValue({
graphService,
value: entityTypes,
valueName: "entityTypes",
});
useSendGraphValue({
graphService,
value: linkedAggregations,
valueName: "linkedAggregations",
});
useSendGraphValue({
graphService,
value: readonly,

@@ -185,8 +181,8 @@ valueName: "readonly",

: undefined })) : null;
return (_jsxs(MockBlockDockProvider, { blockEntity: blockEntity, blockInfo: blockInfo ?? {
return (_jsxs(MockBlockDockProvider, { blockEntitySubgraph: blockEntitySubgraph, blockInfo: blockInfo ?? {
blockType: {
entryPoint: blockType,
},
}, blockSchema: blockSchema, datastore: datastore, debugMode: debugMode, readonly: readonly, setReadonly: setReadonly, setDebugMode: setDebugMode, setEntityIdOfEntityForBlock: setEntityIdOfEntityForBlock, updateEntity: graphServiceCallbacks.updateEntity, children: [_jsx(HookPortals, { hooks: hooks }), _jsx("div", { ref: wrapperRef, children: _jsx(Suspense, { children: hideDebugToggle && !debugMode ? (blockRenderer) : (_jsx(MockBlockDockUi, { children: blockRenderer })) }) })] }));
}, graph: mockDatastore.graph, debugMode: debugMode, readonly: readonly, setReadonly: setReadonly, setDebugMode: setDebugMode, setEntityEditionIdOfEntityForBlock: setEntityEditionIdOfEntityForBlock, updateEntity: graphServiceCallbacks.updateEntity, children: [_jsx(HookPortals, { hooks: hooks }), _jsx("div", { ref: wrapperRef, children: _jsx(Suspense, { children: hideDebugToggle && !debugMode ? (blockRenderer) : (_jsx(MockBlockDockUi, { children: blockRenderer })) }) })] }));
};
//# sourceMappingURL=mock-block-dock.js.map

@@ -1,24 +0,15 @@

import { BlockGraph, EmbedderGraphMessageCallbacks, Entity, EntityType, Link, LinkedAggregation, LinkedAggregationDefinition } from "@blockprotocol/graph";
import { Entity, EntityEditionId } from "@blockprotocol/graph";
import { Dispatch, SetStateAction } from "react";
import { MockData } from "./use-mock-block-props/use-mock-datastore";
import { MockDatastore } from "./datastore/use-mock-datastore";
export type MockBlockHookArgs = {
blockEntity?: Entity;
blockSchema?: Partial<EntityType>;
blockEntityEditionId?: EntityEditionId;
initialEntities?: Entity[];
initialEntityTypes?: EntityType[];
initialLinks?: Link[];
initialLinkedAggregations?: LinkedAggregationDefinition[];
readonly: boolean;
};
export type MockBlockHookResult = {
blockEntity: Entity;
blockGraph: BlockGraph;
blockSchema?: Partial<EntityType>;
datastore: MockData;
entityTypes: EntityType[];
graphServiceCallbacks: Required<EmbedderGraphMessageCallbacks>;
linkedAggregations: LinkedAggregation[];
blockEntityEditionId: EntityEditionId;
mockDatastore: MockDatastore;
readonly: boolean;
setReadonly: Dispatch<SetStateAction<boolean>>;
setEntityIdOfEntityForBlock: Dispatch<SetStateAction<string>>;
setEntityEditionIdOfEntityForBlock: Dispatch<SetStateAction<EntityEditionId>>;
};

@@ -29,9 +20,6 @@ /**

* See README.md for usage instructions.
* @param [blockEntity] the block's own starting properties, if any
* @param [blockSchema] - The schema for the block entity
* @param [blockEntityEditionId] the `EntityEditionId` of the block's own starting entity, if any
* @param [initialEntities] - The entities to include in the data store (NOT the block entity, which is always provided)
* @param [initialEntityTypes] - The entity types to include in the data store (NOT the block's type, which is always provided)
* @param [initialLinks] - The links to include in the data store
* @param [initialLinkedAggregations] - The linkedAggregation DEFINITIONS to include in the data store (results will be resolved automatically)
*/
export declare const useMockBlockProps: ({ blockEntity: externalBlockEntity, blockSchema: externalBlockSchema, initialEntities, initialEntityTypes, initialLinks, initialLinkedAggregations, readonly: externalReadonly, }: MockBlockHookArgs) => MockBlockHookResult;
export declare const useMockBlockProps: ({ blockEntityEditionId: externalBlockEntityEditionId, initialEntities, readonly: externalReadonly, }: MockBlockHookArgs) => MockBlockHookResult;
import { useMemo } from "react";
import { mockData as initialMockData } from "./data";
import { useMockDatastore, } from "./datastore/use-mock-datastore";
import { useDefaultState } from "./use-default-state";
import { useLinkFields } from "./use-mock-block-props/use-link-fields";
import { useMockDatastore, } from "./use-mock-block-props/use-mock-datastore";
/**

@@ -10,91 +9,52 @@ * A hook to generate Block Protocol properties and callbacks for use in testing blocks.

* See README.md for usage instructions.
* @param [blockEntity] the block's own starting properties, if any
* @param [blockSchema] - The schema for the block entity
* @param [blockEntityEditionId] the `EntityEditionId` of the block's own starting entity, if any
* @param [initialEntities] - The entities to include in the data store (NOT the block entity, which is always provided)
* @param [initialEntityTypes] - The entity types to include in the data store (NOT the block's type, which is always provided)
* @param [initialLinks] - The links to include in the data store
* @param [initialLinkedAggregations] - The linkedAggregation DEFINITIONS to include in the data store (results will be resolved automatically)
*/
export const useMockBlockProps = ({ blockEntity: externalBlockEntity, blockSchema: externalBlockSchema, initialEntities, initialEntityTypes, initialLinks, initialLinkedAggregations, readonly: externalReadonly, }) => {
const [entityIdOfEntityForBlock, setEntityIdOfEntityForBlock] = useDefaultState(externalBlockEntity?.entityId ?? "");
export const useMockBlockProps = ({ blockEntityEditionId: externalBlockEntityEditionId, initialEntities,
// initialLinkedAggregations,
readonly: externalReadonly, }) => {
const [entityEditionIdOfEntityForBlock, setEntityEditionIdOfEntityForBlock] = useDefaultState(externalBlockEntityEditionId ?? {
baseId: "",
versionId: new Date().toISOString(),
});
const [readonly, setReadonly] = useDefaultState(externalReadonly);
const { initialBlockEntity, mockData } = useMemo(() => {
const entityTypeId = externalBlockEntity?.entityTypeId ?? "block-type-1";
const blockEntityType = {
entityTypeId,
schema: {
title: "BlockType",
type: "object",
$schema: "https://json-schema.org/draft/2019-09/schema",
$id: "http://localhost/blockType1",
...(externalBlockSchema ?? {}),
},
const { mockData } = useMemo(() => {
const nextMockData = {
entities: [...(initialEntities ?? initialMockData.entities)],
// linkedAggregationDefinitions:
// initialLinkedAggregations ??
// initialMockData.linkedAggregationDefinitions,
};
const newBlockEntity = {
entityId: "block1",
entityTypeId,
properties: {},
};
if (externalBlockEntity && Object.keys(externalBlockEntity).length > 0) {
Object.assign(newBlockEntity, externalBlockEntity);
if (nextMockData.entities.length === 0) {
throw new Error(`Mock data didn't contain any entities, it has to at least contain the block entity`);
}
const nextMockData = {
entities: [
newBlockEntity,
...(initialEntities ?? initialMockData.entities),
],
entityTypes: [
blockEntityType,
...(initialEntityTypes ?? initialMockData.entityTypes),
],
links: initialLinks ?? initialMockData.links,
linkedAggregationDefinitions: initialLinkedAggregations ??
initialMockData.linkedAggregationDefinitions,
};
return { initialBlockEntity: newBlockEntity, mockData: nextMockData };
let blockEntity;
if (externalBlockEntityEditionId) {
blockEntity = nextMockData.entities.find((entity) => entity.metadata.editionId.baseId ===
externalBlockEntityEditionId.baseId &&
entity.metadata.editionId.versionId ===
externalBlockEntityEditionId.versionId);
if (blockEntity === undefined) {
throw new Error(`Mock data didn't contain the given block entity edition ID: ${JSON.stringify(externalBlockEntityEditionId)}`);
}
}
else {
blockEntity = nextMockData.entities[0];
setEntityEditionIdOfEntityForBlock(blockEntity.metadata.editionId);
}
return { mockData: nextMockData };
}, [
externalBlockEntity,
externalBlockSchema,
externalBlockEntityEditionId,
initialEntities,
initialEntityTypes,
initialLinks,
initialLinkedAggregations,
setEntityEditionIdOfEntityForBlock,
// initialLinkedAggregations,
]);
const datastore = useMockDatastore(mockData, readonly);
const { entities, entityTypes, graphServiceCallbacks, links, linkedAggregationDefinitions, } = datastore;
const latestBlockEntity = useMemo(() => {
return (entities.find((entity) => entity.entityId === entityIdOfEntityForBlock) ??
// fallback in case the entityId of the wrapped component is updated by updating its props
mockData.entities.find((entity) => entity.entityId === initialBlockEntity.entityId));
}, [
entities,
initialBlockEntity.entityId,
mockData.entities,
entityIdOfEntityForBlock,
]);
if (!latestBlockEntity) {
throw new Error("Cannot find block entity. Did it delete itself?");
}
// construct BP-specified link fields from the links and linkedAggregations in the datastore
const { blockGraph, linkedAggregations } = useLinkFields({
entities,
links,
linkedAggregationDefinitions,
startingEntity: latestBlockEntity,
});
// @todo we don't do anything with this type except check it exists - do we need to do this?
const latestBlockEntityType = useMemo(() => entityTypes.find((entityType) => entityType.entityTypeId === latestBlockEntity.entityTypeId), [entityTypes, latestBlockEntity.entityTypeId]);
if (!latestBlockEntityType) {
throw new Error("Cannot find block entity type. Has it been deleted?");
}
const mockDatastore = useMockDatastore(mockData, readonly);
return {
blockEntity: latestBlockEntity,
blockGraph,
blockSchema: externalBlockSchema,
datastore,
entityTypes,
graphServiceCallbacks,
linkedAggregations,
blockEntityEditionId: entityEditionIdOfEntityForBlock,
mockDatastore,
// linkedAggregations,
readonly,
setEntityIdOfEntityForBlock,
setEntityEditionIdOfEntityForBlock,
setReadonly,

@@ -101,0 +61,0 @@ };

@@ -1,6 +0,18 @@

import { AggregateEntitiesData, AggregateEntitiesResult, AggregateEntityTypesData, Entity, EntityType } from "@blockprotocol/graph";
import { AggregateEntitiesData, AggregateEntitiesResult, AggregateEntityTypesData, AggregateEntityTypesResult, Entity, EntityType, Subgraph, SubgraphRootTypes } from "@blockprotocol/graph";
type TupleEntry<T extends readonly unknown[], I extends unknown[] = [], R = never> = T extends readonly [infer Head, ...infer Tail] ? TupleEntry<Tail, [...I, unknown], R | [`${I["length"]}`, Head]> : R;
type ObjectEntry<T extends {}> = T extends object ? {
[K in keyof T]: [K, Required<T>[K]];
}[keyof T] extends infer E ? E extends [infer K, infer V] ? K extends string | number ? [`${K}`, V] : never : never : never : never;
export type Entry<T extends {}> = T extends readonly [unknown, ...unknown[]] ? TupleEntry<T> : T extends ReadonlyArray<infer U> ? [`${number}`, U] : ObjectEntry<T>;
/** `Object.entries` analogue which returns a well-typed array */
export declare function typedEntries<T extends {}>(object: T): ReadonlyArray<Entry<T>>;
export declare const get: (obj: unknown, path: string | string[], defaultValue?: undefined) => unknown;
export declare const set: (obj: {}, path: string | string[], value: unknown) => void;
export declare const debounce: <T extends (...args: any[]) => any>(func: T, delayMs: number) => (...args: Parameters<T>) => void;
export declare function filterAndSortEntitiesOrTypes(entities: Entity[], payload: AggregateEntitiesData): AggregateEntitiesResult<Entity>;
export declare function filterAndSortEntitiesOrTypes(entities: EntityType[], payload: AggregateEntityTypesData): AggregateEntitiesResult<EntityType>;
export type FilterResult<T extends Entity | EntityType = Entity | EntityType> = {
results: T[];
operation: AggregateEntitiesResult<Subgraph<SubgraphRootTypes["entity"]>>["operation"] | AggregateEntityTypesResult<Subgraph<SubgraphRootTypes["entityType"]>>["operation"];
};
export declare function filterAndSortEntitiesOrTypes(entities: Entity[], payload: AggregateEntitiesData): FilterResult<Entity>;
export declare function filterAndSortEntitiesOrTypes(entities: EntityType[], payload: AggregateEntityTypesData): FilterResult<EntityType>;
export {};

@@ -0,1 +1,5 @@

/** `Object.entries` analogue which returns a well-typed array */
export function typedEntries(object) {
return Object.entries(object);
}
// Saves us from using heavy lodash dependency

@@ -42,3 +46,3 @@ // Source: https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_get

return entities.filter((entity) => {
if (entityTypeId && entityTypeId !== entity.entityTypeId) {
if (entityTypeId && entityTypeId !== entity.metadata.entityTypeId) {
return false;

@@ -141,3 +145,3 @@ }

if (entityTypeIdFilter) {
results = results.filter((entity) => entity.entityTypeId === entityTypeIdFilter);
results = results.filter((entity) => entity.metadata.entityTypeId === entityTypeIdFilter);
}

@@ -144,0 +148,0 @@ const totalCount = results.length;

@@ -1,1 +0,1 @@

export declare const MOCK_BLOCK_DOCK_VERSION = "0.0.39";
export declare const MOCK_BLOCK_DOCK_VERSION = "0.1.0";

@@ -1,2 +0,2 @@

export const MOCK_BLOCK_DOCK_VERSION = "0.0.39";
export const MOCK_BLOCK_DOCK_VERSION = "0.1.0";
//# sourceMappingURL=version.js.map
{
"name": "mock-block-dock",
"version": "0.0.39",
"version": "0.1.0-20230124234232",
"description": "A mock embedding application for Block Protocol blocks",

@@ -41,4 +41,5 @@ "keywords": [

"@blockprotocol/core": "0.0.13",
"@blockprotocol/graph": "0.0.19",
"@blockprotocol/hook": "0.0.9",
"@blockprotocol/graph": "0.1.0-20230124234232",
"@blockprotocol/hook": "0.1.0-20230124234232",
"@blockprotocol/type-system": "0.0.4-20230124234232",
"@emotion/react": "^11.10.0",

@@ -48,3 +49,3 @@ "@emotion/styled": "^11.10.0",

"@mui/material": "^5.10.4",
"ajv": "^8.9.0",
"ajv": "^8.11.2",
"echarts": "^5.3.3",

@@ -51,0 +52,0 @@ "react-json-view": "^1.21.3",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet