MCPcopy Create free account
hub / github.com/hashintel/hash / createEntity

Function createEntity

apps/hash-api/src/graph/knowledge/primitive/entity.ts:104–161  ·  view source on GitHub ↗
(
  ...args: Parameters<CreateEntityFunction<Properties>>
)

Source from the content-addressed store, hash-verified

102 * Create an entity.
103 */
104export const createEntity = async <
105 Properties extends TypeIdsAndPropertiesForEntity,
106>(
107 ...args: Parameters<CreateEntityFunction<Properties>>
108): ReturnType<CreateEntityFunction<Properties>> => {
109 const [context, authentication, params] = args;
110 const { outgoingLinks, ...createParams } = params;
111
112 const { graphApi, provenance } = context;
113 const { actorId } = authentication;
114
115 let properties = params.properties;
116
117 for (const beforeCreateHook of beforeCreateEntityHooks) {
118 if (createParams.entityTypeIds.includes(beforeCreateHook.entityTypeId)) {
119 const { properties: hookReturnedProperties } =
120 await beforeCreateHook.callback({
121 context,
122 properties,
123 authentication,
124 });
125
126 properties = hookReturnedProperties;
127 }
128 }
129
130 const entity = await HashEntity.create<Properties>(
131 graphApi,
132 { actorId },
133 {
134 ...createParams,
135 properties,
136 provenance,
137 },
138 );
139
140 for (const createOutgoingLinkParams of outgoingLinks ?? []) {
141 await createLinkEntity(context, authentication, {
142 ...createOutgoingLinkParams,
143 linkData: {
144 ...createOutgoingLinkParams.linkData,
145 leftEntityId: entity.metadata.recordId.entityId,
146 },
147 });
148 }
149
150 for (const afterCreateHook of afterCreateEntityHooks) {
151 if (entity.metadata.entityTypeIds.includes(afterCreateHook.entityTypeId)) {
152 void afterCreateHook.callback({
153 context,
154 entity,
155 authentication,
156 });
157 }
158 }
159
160 return entity;
161};

Callers 4

makeEntityFunction · 0.90
oAuthLinearCallbackFunction · 0.90
googleOAuthCallbackFunction · 0.90
createOrgFunction · 0.90

Calls 1

createLinkEntityFunction · 0.90

Tested by

no test coverage detected