1+ /**
2+ * @file This file is Ellyse's exploration into the interactions between
3+ * charms, cells, and documents, and how they relate to common memory.
4+ *
5+ * I'm starting from the bottom (common memory) up and purposely calling
6+ * APIs that would normally call into common memory.
7+ *
8+ */
19import { CharmManager , Charm } from "../common-charm/src/charm.ts" ;
210import { Cell } from "../common-runner/src/cell.ts" ;
311import { DocImpl , getDoc } from "../common-runner/src/doc.ts" ;
412import { EntityId } from "../common-runner/src/cell-map.ts" ;
513import { storage } from "../common-charm/src/storage.ts" ;
614import { getSpace , Space } from "../common-runner/src/space.ts" ;
715
8- const replica = "ellyse6 " ;
16+ const replica = "ellyse7 " ;
917const TOOLSHED_API_URL = "https://toolshed.saga-castor.ts.net/" ;
1018
11- // i'm running common memory locally, so connect to it directly
12- const BASE_URL = "http://localhost:8000"
13-
1419// simple log function
1520const log : < T > ( s : T , prefix ?: string ) => void = ( s , prefix ?) =>
1621 console . log ( "-------------\n" + ( prefix ? prefix : "" ) + ":\n" + JSON . stringify ( s , null , 2 ) ) ;
@@ -21,22 +26,23 @@ function createCell(space: Space): Cell<Charm> {
2126 UI : "someui" ,
2227 "somekey" : "some value" ,
2328 } ;
29+
30+ // make this a DocImpl<Charm> because we need to return a Cell<Charm> since
31+ // that's what CharmManger.add() needs later on
2432 const myDoc : DocImpl < Charm > = getDoc < Charm > ( myCharm , crypto . randomUUID ( ) , space ) ;
25- log ( myDoc , "mydoc, should have name and ui and `somekey`" ) ;
2633 return myDoc . asCell ( ) ;
2734}
2835
2936async function main ( ) {
30-
3137 // create a charm manager to start things off
3238 const charmManager = new CharmManager ( replica ) ;
3339 log ( charmManager , "charmManager" ) ;
3440
3541 // let's try to create a cell
3642 const space : Space = getSpace ( replica ) ;
3743 const cell : Cell < Charm > = createCell ( space ) ;
38- log ( cell , "same mydoc but asCell ()" ) ;
39-
44+ log ( cell . get ( ) , "cell value from Cell.get ()" ) ;
45+
4046 // this feels like magic and wrong,
4147 // but we crash in the next CharmManager.add() if this isn't set
4248 storage . setRemoteStorage (
0 commit comments