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

@blockprotocol/graph

Package Overview
Dependencies
Maintainers
7
Versions
112
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blockprotocol/graph - npm Package Compare versions

Comparing version 0.2.3-canary-20230413145831 to 0.3.0

1

dist/cjs/codegen/context/postprocess.d.ts

@@ -55,2 +55,3 @@ import { DataType, EntityType, PropertyType, VersionedUrl } from "@blockprotocol/type-system/slim";

logTrace(message: string): void;
addDependentIdentifierInFile(identifier: string, path: string): void;
defineIdentifierInFile(identifier: string, { definingPath, compiledContents, dependentOnIdentifiers, }: {

@@ -57,0 +58,0 @@ definingPath: string;

9

dist/cjs/codegen/postprocess/generate-link-and-target-definitions.d.ts

@@ -1,12 +0,3 @@

import { VersionedUrl } from "@blockprotocol/type-system/slim";
import { PostprocessContext } from "../context/postprocess.js";
/**
* Generates definitions associated with the outgoing links and their targets of a given entity
*
* @param fileName
* @param entityTypeId
* @param context
*/
export declare const generateOutgoingLinkAndTargetDefinitionsForEntity: (fileName: string, entityTypeId: VersionedUrl, context: PostprocessContext) => void;
/**
* Generates types for the definition of various associated `LinkEntityAndTarget` `Entity` kinds, alongside their entity type definitions.

@@ -13,0 +4,0 @@ *

@@ -13,3 +13,3 @@ import { LitElement } from "lit";

* It starts off undefined and will be available once the initial exchange of messages has taken place (handled internally)
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list of available messages
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list of available messages
*/

@@ -26,3 +26,3 @@ protected graphModule?: GraphBlockHandler;

* One such message is 'graph.blockEntitySubgraph', which is a graph rooted at the block entity.
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list
*/

@@ -29,0 +29,0 @@ graph: {

@@ -18,3 +18,3 @@ /**

* One such message is 'graph.blockEntity', which is a data entity fitting the block's schema (its type).
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list
*/

@@ -21,0 +21,0 @@ graph: {

@@ -12,3 +12,3 @@ import { MessageCallback, MessageReturn } from "@blockprotocol/core";

* One such message is 'graph.blockEntitySubgraph', which is a data entity fitting the block's schema (its type).
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list
*/

@@ -15,0 +15,0 @@ graph: {

@@ -13,3 +13,3 @@ import { LitElement } from "lit";

* It starts off undefined and will be available once the initial exchange of messages has taken place (handled internally)
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list of available messages
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list of available messages
*/

@@ -28,3 +28,3 @@ protected graphModule?: GraphBlockHandler;

* One such message is 'graph.blockEntitySubgraph', which is a graph rooted at the block entity.
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list
*/

@@ -31,0 +31,0 @@ graph: {

@@ -15,3 +15,3 @@ /**

* One such message is 'graph.blockEntity', which is a data entity fitting the block's schema (its type).
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list
*/

@@ -18,0 +18,0 @@ graph: {

@@ -445,2 +445,7 @@ import * as path from 'node:path';

}
addDependentIdentifierInFile(identifier, path) {
var _a;
(_a = this.filesToDependentIdentifiers)[path] ?? (_a[path] = new Set());
this.filesToDependentIdentifiers[path].add(identifier);
}
defineIdentifierInFile(identifier, { definingPath, compiledContents, dependentOnIdentifiers, }, locallyImportable) {

@@ -562,7 +567,29 @@ var _a, _b;

const fetchTypeAsJson = (versionedUrl) => fetch(versionedUrl, {
headers: {
accept: "application/json",
},
}).then((resp) => resp.json());
const MAX_RETRIES = 3;
const RETRY_DELAY_MS = 100;
const fetchTypeAsJson = async (versionedUrl) => {
for (let retry = 0; retry < MAX_RETRIES; retry++) {
const delay = RETRY_DELAY_MS * retry;
// This will be 0 for the first iteration, a bit superfluous but keeps the code logic simple
await new Promise((resolve) => {
setTimeout(resolve, delay);
});
try {
const response = await fetch(versionedUrl, {
headers: {
accept: "application/json",
},
});
if (!response.ok) {
continue;
}
return await response.json();
}
catch (err) {
if (retry === MAX_RETRIES - 1) {
throw err;
}
}
}
};

@@ -812,10 +839,12 @@ const isObjectWithKindString = (obj, kind) => {

const generateDefinitionForEntity = (fileName, entityTypeId, context) => {
const typeName = mustBeDefined(context.entityTypes[entityTypeId]).title;
const generateEntityDefinitionForEntityType = (entityTypeId, title, context) => {
const typeName = title;
const isLinkType = mustBeDefined(context.linkTypeMap[entityTypeId]);
const linkSuffix = isLinkType ? ` & { linkData: LinkData }` : "";
const entityName = entityDefinitionNameForEntityType(typeName);
const compiledContents = `\nexport type ${entityName} = Entity<${typeName}>${linkSuffix}\n`;
return { entityName, isLinkType, compiledContents };
};
const allocateEntityDefinitionToFile = (fileName, entityName, isLinkType, compiledContents, context) => {
context.logTrace(`Adding${isLinkType ? " link " : " "}entity definition for ${entityName}`);
mustBeDefined(context.filesToContents[fileName]);
const compiledContents = `\nexport type ${entityName} = Entity<${typeName}>${linkSuffix}\n`;
context.defineIdentifierInFile(entityName, {

@@ -838,7 +867,19 @@ definingPath: fileName,

]));
for (const [file, definedIdentifiers] of Object.entries(context.filesToDefinedIdentifiers)) {
for (const identifier of definedIdentifiers) {
const entityTypeIdsToEntityDefinitions = Object.fromEntries(typedEntries(context.entityTypes).map(([entityTypeId, { title }]) => {
return [
entityTypeId,
generateEntityDefinitionForEntityType(entityTypeId, title, context),
];
}));
for (const [file, dependentIdentifiers] of typedEntries(context.filesToDependentIdentifiers)) {
for (const identifier of dependentIdentifiers) {
const entityTypeId = entityTypeIdentifiersToIds[identifier];
if (entityTypeId) {
generateDefinitionForEntity(file, entityTypeId, context);
const { entityName, isLinkType, compiledContents } = mustBeDefined(entityTypeIdsToEntityDefinitions[entityTypeId]);
if (context.filesToDefinedIdentifiers[file]?.has(identifier)) {
allocateEntityDefinitionToFile(file, entityName, isLinkType, compiledContents, context);
}
else {
context.addDependentIdentifierInFile(entityName, file);
}
}

@@ -857,3 +898,3 @@ }

const individualOutgoingLinkAndTargetDefinition = (sourceName, linkIdentifier, targetIdentifiers) => {
const identifier = `${sourceName}${linkIdentifier}Links`;
const identifier = `${sourceName}${linkIdentifier}Link`;
const targetUnion = targetIdentifiers.join(" | ");

@@ -908,7 +949,7 @@ const compiledContents = `export type ${identifier} = { linkEntity: ${linkIdentifier}; rightEntity: ${targetUnion} }`;

*
* @param fileName
* @param entityName
* @param entityTypeId
* @param context
*/
const generateOutgoingLinkAndTargetDefinitionsForEntity = (fileName, entityTypeId, context) => {
const generateOutgoingLinkAndTargetDefinitionsForEntity = (entityName, entityTypeId, context) => {
const entityType = mustBeDefined(context.entityTypes[entityTypeId]);

@@ -934,3 +975,2 @@ const mappedLinkAndTargetIdentifiers = {};

}
const entityName = entityDefinitionNameForEntityType(entityType.title);
const linkTypeIdsTolinkAndTargets = Object.fromEntries(typedEntries(mappedLinkAndTargetIdentifiers).map(([linkTypeId, { linkIdentifier, targetIdentifiers }]) => {

@@ -950,8 +990,12 @@ if (targetIdentifiers.length === 0) {

const linkAndTargetsUnion = linkAndTargetsUnionDefinition(entityName, linkAndTargetIdentifiers);
context.logTrace(`Adding outgoing link and target definitions for ${entityName}`);
for (const { identifier, compiledContents, dependentOnIdentifiers } of [
return {
entityName,
lookup,
linkAndTargetsUnion,
...linkAndTargets,
]) {
linkAndTargets,
};
};
const allocateOutgoingLinkAndTargetDefinitionsToFile = (fileName, entityName, definitions, context) => {
context.logTrace(`Adding outgoing link and target definitions for ${entityName}`);
for (const { identifier, compiledContents, dependentOnIdentifiers, } of definitions) {
context.defineIdentifierInFile(identifier, {

@@ -975,7 +1019,26 @@ definingPath: fileName,

]));
for (const [file, definedIdentifiers] of Object.entries(context.filesToDefinedIdentifiers)) {
for (const identifier of definedIdentifiers) {
const entityTypeId = entityTypeIdentifiersToIds[identifier];
const entityTypeIdsToOutgoingLinkAndTargetDefinitions = Object.fromEntries(typedEntries(context.entityTypes).map(([entityTypeId, { title }]) => {
const entityName = entityDefinitionNameForEntityType(title);
return [
entityTypeId,
generateOutgoingLinkAndTargetDefinitionsForEntity(entityName, entityTypeId, context),
];
}));
for (const [file, dependentIdentifiers] of typedEntries(context.filesToDependentIdentifiers)) {
for (const dependentIdentifier of dependentIdentifiers) {
const entityTypeId = entityTypeIdentifiersToIds[dependentIdentifier];
if (entityTypeId) {
generateOutgoingLinkAndTargetDefinitionsForEntity(file, entityTypeId, context);
const { entityName, lookup, linkAndTargets, linkAndTargetsUnion } = mustBeDefined(entityTypeIdsToOutgoingLinkAndTargetDefinitions[entityTypeId]);
if (context.filesToDefinedIdentifiers[file]?.has(dependentIdentifier)) {
allocateOutgoingLinkAndTargetDefinitionsToFile(file, entityName, [lookup, linkAndTargetsUnion, ...linkAndTargets], context);
}
else {
for (const { identifier } of [
lookup,
linkAndTargetsUnion,
...linkAndTargets,
]) {
context.addDependentIdentifierInFile(identifier, file);
}
}
}

@@ -1234,4 +1297,7 @@ }

// revisions of the types
// We want this process to be deterministic so we sort by Base URL
const baseUrlToTypesEntries = typedEntries(baseUrlToTypes);
baseUrlToTypesEntries.sort(([baseUrlA, _A], [baseUrlB, _B]) => baseUrlA.localeCompare(baseUrlB));
/* @todo - Add option to pass in a named capture-group regex which can extract more components */
for (const [index, [_baseUrl, typesOfBaseUrl]] of typedEntries(typedEntries(baseUrlToTypes))) {
for (const [index, [_baseUrl, typesOfBaseUrl]] of typedEntries(baseUrlToTypesEntries)) {
if (typesOfBaseUrl.length > 1) {

@@ -1238,0 +1304,0 @@ for (const currentTypeRevision of typesOfBaseUrl) {

@@ -55,2 +55,3 @@ import { DataType, EntityType, PropertyType, VersionedUrl } from "@blockprotocol/type-system/slim";

logTrace(message: string): void;
addDependentIdentifierInFile(identifier: string, path: string): void;
defineIdentifierInFile(identifier: string, { definingPath, compiledContents, dependentOnIdentifiers, }: {

@@ -57,0 +58,0 @@ definingPath: string;

@@ -1,12 +0,3 @@

import { VersionedUrl } from "@blockprotocol/type-system/slim";
import { PostprocessContext } from "../context/postprocess.js";
/**
* Generates definitions associated with the outgoing links and their targets of a given entity
*
* @param fileName
* @param entityTypeId
* @param context
*/
export declare const generateOutgoingLinkAndTargetDefinitionsForEntity: (fileName: string, entityTypeId: VersionedUrl, context: PostprocessContext) => void;
/**
* Generates types for the definition of various associated `LinkEntityAndTarget` `Entity` kinds, alongside their entity type definitions.

@@ -13,0 +4,0 @@ *

@@ -830,3 +830,3 @@ import { LitElement } from 'lit';

* One such message is 'graph.blockEntitySubgraph', which is a graph rooted at the block entity.
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list
*/

@@ -833,0 +833,0 @@ graph: { type: Object },

@@ -827,3 +827,3 @@ import { LitElement } from 'lit';

* One such message is 'graph.blockEntitySubgraph', which is a graph rooted at the block entity.
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list
*/

@@ -830,0 +830,0 @@ graph: { type: Object },

@@ -13,3 +13,3 @@ import { LitElement } from "lit";

* It starts off undefined and will be available once the initial exchange of messages has taken place (handled internally)
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list of available messages
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list of available messages
*/

@@ -26,3 +26,3 @@ protected graphModule?: GraphBlockHandler;

* One such message is 'graph.blockEntitySubgraph', which is a graph rooted at the block entity.
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list
*/

@@ -29,0 +29,0 @@ graph: {

@@ -18,3 +18,3 @@ /**

* One such message is 'graph.blockEntity', which is a data entity fitting the block's schema (its type).
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list
*/

@@ -21,0 +21,0 @@ graph: {

@@ -12,3 +12,3 @@ import { MessageCallback, MessageReturn } from "@blockprotocol/core";

* One such message is 'graph.blockEntitySubgraph', which is a data entity fitting the block's schema (its type).
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list
*/

@@ -15,0 +15,0 @@ graph: {

@@ -13,3 +13,3 @@ import { LitElement } from "lit";

* It starts off undefined and will be available once the initial exchange of messages has taken place (handled internally)
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list of available messages
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list of available messages
*/

@@ -28,3 +28,3 @@ protected graphModule?: GraphBlockHandler;

* One such message is 'graph.blockEntitySubgraph', which is a graph rooted at the block entity.
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list
*/

@@ -31,0 +31,0 @@ graph: {

@@ -15,3 +15,3 @@ /**

* One such message is 'graph.blockEntity', which is a data entity fitting the block's schema (its type).
* @see https://blockprotocol.org/docs/spec/graph-module#message-definitions for a full list
* @see https://blockprotocol.org/spec/graph#message-definitions for a full list
*/

@@ -18,0 +18,0 @@ graph: {

{
"name": "@blockprotocol/graph",
"version": "0.2.3-canary-20230413145831",
"version": "0.3.0",
"description": "Implementation of the Block Protocol Graph service specification for blocks and embedding applications",

@@ -133,3 +133,3 @@ "keywords": [

"dependencies": {
"@blockprotocol/core": "0.1.3-canary-20230413145831",
"@blockprotocol/core": "0.1.2",
"@blockprotocol/type-system": "0.1.1",

@@ -136,0 +136,0 @@ "ajv": "^8.11.2",

@@ -75,3 +75,3 @@ ## Block Protocol – Graph module

See the [here](https://blockprotocol.org/docs/spec/graph-module#message-definitions) or check the TypeScript types for message signatures.
See the [here](https://blockprotocol.org/spec/graph#message-definitions) or check the TypeScript types for message signatures.

@@ -78,0 +78,0 @@ ```typescript

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc