Skip to content

Commit a59e891

Browse files
authored
Simplify interface for getCellFromLink (#634)
now that cell links have spaces, let's simplify the interface for getCellFromLink
1 parent 8cd7ac4 commit a59e891

File tree

4 files changed

+13
-22
lines changed

4 files changed

+13
-22
lines changed

cli/write-to-authcell.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
// Load .env file
2-
import {
3-
type CellLink,
4-
getCellFromCellLink,
5-
storage,
6-
} from "@commontools/runner";
2+
import { type CellLink, getCellFromLink, storage } from "@commontools/runner";
73
import { parseArgs } from "@std/cli/parse-args";
84

95
const TOOLSHED_API_URL = Deno.env.get("TOOLSHED_API_URL") ||
@@ -23,11 +19,12 @@ async function main(
2319

2420
const doc = await storage.syncCellById(replica, cellId, true);
2521
const authCellEntity = {
22+
space: replica,
2623
cell: doc,
2724
path: ["argument", "auth"],
2825
} satisfies CellLink;
2926

30-
const authCell = getCellFromCellLink(replica, authCellEntity);
27+
const authCell = getCellFromLink(authCellEntity);
3128
// authCell.set({ token: "wat" });
3229
await storage.synced();
3330

runner/src/cell.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -214,27 +214,27 @@ export function getCellFromEntityId(
214214
return createCell(doc, path, log, schema);
215215
}
216216

217-
export function getCellFromCellLink<T>(
218-
space: string,
217+
export function getCellFromLink<T>(
219218
docLink: CellLink,
220219
schema?: JSONSchema,
221220
log?: ReactivityLog,
222221
): Cell<T>;
223-
export function getCellFromCellLink<S extends JSONSchema = JSONSchema>(
224-
space: string,
222+
export function getCellFromLink<S extends JSONSchema = JSONSchema>(
225223
docLink: CellLink,
226224
schema: S,
227225
log?: ReactivityLog,
228226
): Cell<Schema<S>>;
229-
export function getCellFromCellLink(
230-
space: string, // TODO(seefeld): Read from DocLink once it's defined there
227+
export function getCellFromLink(
231228
docLink: CellLink,
232229
schema?: JSONSchema,
233230
log?: ReactivityLog,
234231
): Cell<any> {
232+
if (!docLink.space) {
233+
throw new Error("Cell link has no space");
234+
}
235235
const doc = isDoc(docLink.cell)
236236
? docLink.cell
237-
: getDocByEntityId(space, getEntityId(docLink.cell)!, true)!;
237+
: getDocByEntityId(docLink.space, getEntityId(docLink.cell)!, true)!;
238238
return createCell(doc, docLink.path, log, schema);
239239
}
240240

runner/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ export type { ReactivityLog } from "./scheduler.ts";
1313
export { getDoc, isDoc } from "./doc.ts";
1414
export {
1515
getCell,
16-
getCellFromCellLink,
1716
getCellFromEntityId,
17+
getCellFromLink,
1818
getImmutableCell,
1919
isCell,
2020
isCellLink,

toolshed/routes/integrations/google-oauth/google-oauth.utils.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { OAuth2Client } from "@cmd-johnson/oauth2-client";
22
import env from "@/env.ts";
3-
import {
4-
type CellLink,
5-
getCellFromCellLink,
6-
storage,
7-
} from "@commontools/runner";
3+
import { type CellLink, getCellFromLink, storage } from "@commontools/runner";
84
import { Context } from "@hono/hono";
95
import { Identity, Signer } from "@commontools/identity";
106
// Types
@@ -169,10 +165,8 @@ export async function getAuthCellAndStorage(docLink: CellLink | string) {
169165

170166
storage.setRemoteStorage(new URL("http://localhost:8000"));
171167

172-
// FIXME(ja): the space should be inferred from the doclink - but it isn't there yet
173168
// FIXME(ja): add the authcell schema!
174-
const authCell = getCellFromCellLink(
175-
parsedDocLink.space, // FIXME(ja): the space should be inferred from the doclink - but it isn't there yet
169+
const authCell = getCellFromLink(
176170
parsedDocLink,
177171
undefined,
178172
);

0 commit comments

Comments
 (0)