Skip to content

Commit fd0e5d5

Browse files
author
Ellyse
committed
exploring how cells and docs get stored
1 parent 38fd78f commit fd0e5d5

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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();

typescript/packages/common-cli/deno.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
"start": "deno run --allow-read --allow-env --allow-net main.ts",
44
"memtest": "deno run --allow-read --allow-env --allow-net memory_test.ts",
55
"test": "deno test"
6+
"charmtest": "deno run --import-map=import_map.json --unstable-sloppy-imports --allow-read --allow-env --allow-net charm_test.ts"
67
}
78
}

typescript/packages/common-cli/memory_test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,10 @@ async function main() {
8383
// now lets try to store a batch of values
8484
console.log("storing all entities");
8585
const result = await storageProvider.send(people_batch);
86-
87-
console.log("sent entity, result: " + JSON.stringify(result, null, 2));
86+
if (result.ok)
87+
console.log("sent entities successfully");
88+
else
89+
console.log("got error: " + JSON.stringify(result.error, null, 2));
8890
}
8991

9092
main();

0 commit comments

Comments
 (0)