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

Function getFileEntity

apps/hash-api/src/storage/index.ts:92–153  ·  view source on GitHub ↗
(
  context: ImpureGraphContext,
  authentication: AuthenticationContext,
  params: { entityId: EntityId; key: string; includeDrafts?: boolean },
)

Source from the content-addressed store, hash-verified

90 blockProtocolPropertyTypes.fileUrl.propertyTypeBaseUrl in entity.properties;
91
92const getFileEntity = async (
93 context: ImpureGraphContext,
94 authentication: AuthenticationContext,
95 params: { entityId: EntityId; key: string; includeDrafts?: boolean },
96) => {
97 const { entityId, key, includeDrafts = false } = params;
98 const [webId, entityUuid] = splitEntityId(entityId);
99
100 const { entities: fileEntityRevisions } = await queryEntities(
101 context,
102 authentication,
103 {
104 filter: {
105 all: [
106 {
107 equal: [{ path: ["uuid"] }, { parameter: entityUuid }],
108 },
109 {
110 equal: [{ path: ["webId"] }, { parameter: webId }],
111 },
112 {
113 equal: [
114 {
115 path: [
116 "properties",
117 systemPropertyTypes.fileStorageKey.propertyTypeBaseUrl,
118 ],
119 },
120 { parameter: key },
121 ],
122 },
123 ],
124 },
125 temporalAxes: fullDecisionTimeAxis,
126 includeDrafts,
127 includePermissions: false,
128 },
129 );
130
131 const latestFileEntityRevision = fileEntityRevisions.reduce<
132 Entity | undefined
133 >((previousLatestRevision, currentRevision) => {
134 if (!previousLatestRevision) {
135 return currentRevision;
136 }
137
138 const currentCreatedAt = new Date(
139 currentRevision.metadata.temporalVersioning.decisionTime.start.limit,
140 );
141
142 const previousLatestRevisionCreatedAt = new Date(
143 previousLatestRevision.metadata.temporalVersioning.decisionTime.start
144 .limit,
145 );
146
147 return previousLatestRevisionCreatedAt < currentCreatedAt
148 ? currentRevision
149 : previousLatestRevision;

Callers 1

Calls 3

splitEntityIdFunction · 0.90
queryEntitiesFunction · 0.90
reduceMethod · 0.80

Tested by

no test coverage detected