Skip to content

Commit a291872

Browse files
author
Ellyse
committed
use Cell<Charm> since thats what CharmManager.add() wants
1 parent 346089f commit a291872

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

typescript/packages/common-cli/charm_test.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { CharmManager, Charm, createStorage } from "@commontools/charm";
1+
import { CharmManager, Charm } from "../common-charm/src/charm.ts";
22
import { Cell } from "../common-runner/src/cell.ts";
3-
import { getDoc } from "../common-runner/src/doc.ts";
3+
import { DocImpl, getDoc } from "../common-runner/src/doc.ts";
44
import { EntityId } from "../common-runner/src/cell-map.ts";
55
import { storage } from "../common-charm/src/storage.ts";
66
import { getSpace, Space } from "../common-runner/src/space.ts";
@@ -13,12 +13,17 @@ const BASE_URL = "http://localhost:8000"
1313

1414
// simple log function
1515
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();
16+
console.log("-------------\n" + (prefix ? prefix : "") + ":\n" + JSON.stringify(s, null, 2));
17+
18+
function createCell(space: Space): Cell<Charm> {
19+
const myCharm: Charm = {
20+
NAME: "mycharm",
21+
UI: "someui",
22+
"somekey": "some value",
23+
};
24+
const myDoc: DocImpl<Charm> = getDoc<Charm>(myCharm, crypto.randomUUID(), space);
25+
log(myDoc, "mydoc, should have name and ui and `somekey`");
26+
return myDoc.asCell();
2227
}
2328

2429
async function main() {
@@ -30,9 +35,10 @@ async function main() {
3035
// let's try to create a cell
3136
const space: Space = getSpace(replica);
3237
const cell: Cell<Charm> = createCell(space);
33-
log(cell, "charmmanager empty cell");
38+
log(cell, "same mydoc but asCell()");
3439

35-
// this feels like magic and wrong
40+
// this feels like magic and wrong,
41+
// but we crash in the next CharmManager.add() if this isn't set
3642
storage.setRemoteStorage(
3743
new URL(TOOLSHED_API_URL)
3844
);

0 commit comments

Comments
 (0)