@@ -316,14 +316,14 @@ export class HypercertOperationsImpl extends EventEmitter<HypercertEvents> imple
316316 * @param hypercertUri - URI of the hypercert
317317 * @param location - Location data
318318 * @param onProgress - Optional progress callback
319- * @returns Promise resolving to location URI
319+ * @returns Promise resolving to location URI and CID
320320 * @internal
321321 */
322322 private async attachLocationWithProgress (
323323 hypercertUri : string ,
324324 location : LocationParams ,
325325 onProgress ?: ( step : ProgressStep ) => void ,
326- ) : Promise < string > {
326+ ) : Promise < CreateResult > {
327327 this . emitProgress ( onProgress , { name : "attachLocation" , status : "start" } ) ;
328328 try {
329329 const locationResult = await this . attachLocation ( hypercertUri , location ) ;
@@ -332,7 +332,7 @@ export class HypercertOperationsImpl extends EventEmitter<HypercertEvents> imple
332332 status : "success" ,
333333 data : { uri : locationResult . uri } ,
334334 } ) ;
335- return locationResult . uri ;
335+ return locationResult ;
336336 } catch ( error ) {
337337 this . emitProgress ( onProgress , { name : "attachLocation" , status : "error" , error : error as Error } ) ;
338338 this . logger ?. warn ( `Failed to attach location: ${ error instanceof Error ? error . message : "Unknown" } ` ) ;
@@ -435,8 +435,8 @@ export class HypercertOperationsImpl extends EventEmitter<HypercertEvents> imple
435435 *
436436 * @remarks
437437 * The operation is not atomic - if a later step fails, earlier records
438- * will still exist. The result object will contain URIs for all
439- * successfully created records .
438+ * will still exist. The returned record reflects the created hypercert,
439+ * including location when attachment succeeds .
440440 *
441441 * **Progress Steps**:
442442 * - `uploadImage`: Image blob upload
@@ -520,7 +520,9 @@ export class HypercertOperationsImpl extends EventEmitter<HypercertEvents> imple
520520 // Step 4: Attach location if provided
521521 if ( params . location ) {
522522 try {
523- result . locationUri = await this . attachLocationWithProgress ( hypercertUri , params . location , params . onProgress ) ;
523+ const { uri, cid } = await this . attachLocationWithProgress ( hypercertUri , params . location , params . onProgress ) ;
524+ result . locationUri = uri ;
525+ result . locationCid = cid ;
524526 } catch {
525527 // Error already logged and progress emitted
526528 }
@@ -1278,6 +1280,8 @@ export class HypercertOperationsImpl extends EventEmitter<HypercertEvents> imple
12781280 async createCollection ( params : CreateCollectionParams ) : Promise < CreateCollectionResult > {
12791281 const createdAt = new Date ( ) . toISOString ( ) ;
12801282
1283+ let locationResult : { uri : string ; cid : string } | undefined ;
1284+
12811285 const collectionRecord : HypercertCollection = {
12821286 $type : HYPERCERT_COLLECTIONS . COLLECTION ,
12831287 title : params . title ,
@@ -1310,7 +1314,7 @@ export class HypercertOperationsImpl extends EventEmitter<HypercertEvents> imple
13101314 }
13111315
13121316 if ( params . location ) {
1313- const locationResult = await this . resolveLocation ( params . location ) ;
1317+ locationResult = await this . resolveLocation ( params . location ) ;
13141318 collectionRecord . location = locationResult ;
13151319 }
13161320
@@ -1333,6 +1337,7 @@ export class HypercertOperationsImpl extends EventEmitter<HypercertEvents> imple
13331337 uri : result . data . uri ,
13341338 cid : result . data . cid ,
13351339 record : collectionRecord ,
1340+ locationUri : locationResult ?. uri ,
13361341 } ;
13371342 this . emit ( "collectionCreated" , createCollectionResult ) ;
13381343 return createCollectionResult ;
@@ -1928,6 +1933,9 @@ export class HypercertOperationsImpl extends EventEmitter<HypercertEvents> imple
19281933 * @returns Promise resolving to location record result
19291934 */
19301935 async attachLocationToProject ( uri : string , location : LocationParams ) : Promise < CreateResult > {
1936+ // Validate it's actually a project
1937+ await this . getProject ( uri ) ;
1938+
19311939 const result = await this . attachLocationToCollection ( uri , location ) ;
19321940 this . emit ( "locationAttachedToProject" , {
19331941 uri : result . uri ,
@@ -1943,6 +1951,9 @@ export class HypercertOperationsImpl extends EventEmitter<HypercertEvents> imple
19431951 * @param uri - AT-URI of the project
19441952 */
19451953 async removeLocationFromProject ( uri : string ) : Promise < void > {
1954+ // Validate it's actually a project
1955+ await this . getProject ( uri ) ;
1956+
19461957 await this . removeLocationFromCollection ( uri ) ;
19471958 this . emit ( "locationRemovedFromProject" , { projectUri : uri } ) ;
19481959 }
0 commit comments