|
| 1 | +import { CharmManager, Charm, createStorage } from "@commontools/charm"; |
| 2 | +import { Cell } from "../common-runner/src/cell.ts"; |
| 3 | +import { getDoc } from "../common-runner/src/doc.ts"; |
| 4 | +import { EntityId } from "../common-runner/src/cell-map.ts"; |
| 5 | +import { storage } from "../common-charm/src/storage.ts"; |
| 6 | +import { getSpace, Space } from "../common-runner/src/space.ts"; |
| 7 | + |
| 8 | +const replica = "ellyse6"; |
| 9 | +const TOOLSHED_API_URL = "https://toolshed.saga-castor.ts.net/"; |
| 10 | + |
| 11 | +// i'm running common memory locally, so connect to it directly |
| 12 | +const BASE_URL = "http://localhost:8000" |
| 13 | + |
| 14 | +// simple log function |
| 15 | +const log: <T>(s: T, prefix?: string) => void = (s, prefix?) => |
| 16 | + console.log((prefix ? prefix : "") + "--------\n" + JSON.stringify(s, null, 2)); |
| 17 | + |
| 18 | +function createCell(space: Space): Cell<any> { |
| 19 | + const emptyDoc = getDoc<number>(10, crypto.randomUUID(), space); |
| 20 | + log(emptyDoc, "empty doc"); |
| 21 | + return emptyDoc.asCell(); |
| 22 | +} |
| 23 | + |
| 24 | +async function main() { |
| 25 | + |
| 26 | + // create a charm manager to start things off |
| 27 | + const charmManager = new CharmManager(replica); |
| 28 | + log(charmManager, "charmManager"); |
| 29 | + |
| 30 | + // let's try to create a cell |
| 31 | + const space: Space = getSpace(replica); |
| 32 | + const cell: Cell<Charm> = createCell(space); |
| 33 | + log(cell, "charmmanager empty cell"); |
| 34 | + |
| 35 | + // this feels like magic and wrong |
| 36 | + storage.setRemoteStorage( |
| 37 | + new URL(TOOLSHED_API_URL) |
| 38 | + ); |
| 39 | + |
| 40 | + // let's add the cell to the charmManager |
| 41 | + await charmManager.add([cell]); |
| 42 | + log(charmManager, "charmmanager after adding cell"); |
| 43 | +} |
| 44 | + |
| 45 | +main(); |
0 commit comments