Skip to content

Commit 2bb1e50

Browse files
committed
also exports constants via builder!
1 parent 5c4f4b7 commit 2bb1e50

File tree

7 files changed

+59
-22
lines changed

7 files changed

+59
-22
lines changed

packages/builder/src/factory.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
*/
44

55
import type {
6-
BuilderFunctions,
6+
BuilderFunctionsAndConstants,
77
Cell,
88
CreateCellFunction,
99
JSONSchema,
1010
} from "./types.ts";
11+
import { AuthSchema, ID, ID_FIELD, NAME, schema, TYPE, UI } from "./types.ts";
1112
import { opaqueRef, stream } from "./opaque-ref.ts";
1213
import { getTopFrame, recipe } from "./recipe.ts";
1314
import { byRef, compute, derive, handler, lift, render } from "./module.ts";
@@ -30,7 +31,7 @@ import { getRecipeEnvironment } from "./env.ts";
3031
*/
3132
export const createBuilder = (
3233
runtime: Runtime,
33-
): BuilderFunctions => {
34+
): BuilderFunctionsAndConstants => {
3435
// Implementation of createCell moved from runner/harness
3536
const createCell: CreateCellFunction = function createCell<T = any>(
3637
schema?: JSONSchema,
@@ -96,5 +97,16 @@ export const createBuilder = (
9697

9798
// Environment
9899
getRecipeEnvironment,
100+
101+
// Constants
102+
ID,
103+
ID_FIELD,
104+
TYPE,
105+
NAME,
106+
UI,
107+
108+
// Schema utilities
109+
schema,
110+
AuthSchema,
99111
};
100112
};

packages/builder/src/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
// Export the factory function
22
export { createBuilder } from "./factory.ts";
3-
export type { BuilderFunctions, BuilderRuntime } from "./types.ts";
3+
export type {
4+
BuilderFunctionsAndConstants as BuilderFunctions,
5+
BuilderRuntime,
6+
} from "./types.ts";
47

58
// Internal functions and exports needed by other packages
69
export {

packages/builder/src/types.ts

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ import type {
2828
StreamFunction,
2929
StrFunction,
3030
} from "./interface.ts";
31+
import {
32+
AuthSchema,
33+
ID,
34+
ID_FIELD,
35+
NAME,
36+
schema,
37+
TYPE,
38+
UI,
39+
} from "./interface.ts";
3140

3241
export { AuthSchema, ID, ID_FIELD, NAME, TYPE, UI } from "./interface.ts";
3342
export type {
@@ -250,7 +259,7 @@ export function markAsStatic(value: unknown): unknown {
250259
}
251260

252261
// Builder functions interface
253-
export interface BuilderFunctions {
262+
export interface BuilderFunctionsAndConstants {
254263
// Recipe creation
255264
recipe: RecipeFunction;
256265

@@ -280,6 +289,17 @@ export interface BuilderFunctions {
280289

281290
// Environment
282291
getRecipeEnvironment: GetRecipeEnvironmentFunction;
292+
293+
// Constants
294+
ID: typeof ID;
295+
ID_FIELD: typeof ID_FIELD;
296+
TYPE: typeof TYPE;
297+
NAME: typeof NAME;
298+
UI: typeof UI;
299+
300+
// Schema utilities
301+
schema: typeof schema;
302+
AuthSchema: typeof AuthSchema;
283303
}
284304

285305
// Runtime interface needed by createCell
@@ -302,4 +322,4 @@ export interface BuilderRuntime {
302322
export type CreateBuilder = (
303323
runtime: BuilderRuntime,
304324
getCellLinkOrThrow?: (value: any) => any,
305-
) => BuilderFunctions;
325+
) => BuilderFunctionsAndConstants;

packages/html/test/html-recipes.test.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { beforeEach, describe, it, afterEach } from "@std/testing/bdd";
1+
import { afterEach, beforeEach, describe, it } from "@std/testing/bdd";
22
import { h, render, VNode } from "../src/index.ts";
3-
import { createBuilder, UI } from "@commontools/builder";
3+
import { createBuilder } from "@commontools/builder";
44
import { Runtime } from "@commontools/runner";
55
import * as assert from "./assert.ts";
66
import { JSDOM } from "jsdom";
@@ -12,6 +12,7 @@ describe("recipes with HTML", () => {
1212
let lift: ReturnType<typeof createBuilder>["lift"];
1313
let recipe: ReturnType<typeof createBuilder>["recipe"];
1414
let str: ReturnType<typeof createBuilder>["str"];
15+
let UI: ReturnType<typeof createBuilder>["UI"];
1516

1617
beforeEach(() => {
1718
// Set up a fresh JSDOM instance for each test
@@ -26,11 +27,11 @@ describe("recipes with HTML", () => {
2627

2728
// Set up runtime
2829
runtime = new Runtime({
29-
storageUrl: "volatile://"
30+
storageUrl: "volatile://",
3031
});
31-
32+
3233
const builder = createBuilder(runtime);
33-
({ lift, recipe, str } = builder);
34+
({ lift, recipe, str, UI } = builder);
3435
});
3536

3637
afterEach(async () => {
@@ -48,7 +49,7 @@ describe("recipes with HTML", () => {
4849
const result = runtime.run(
4950
simpleRecipe,
5051
{ value: 5 },
51-
runtime.documentMap.getDoc(undefined, "simple-ui-result", "test")
52+
runtime.documentMap.getDoc(undefined, "simple-ui-result", "test"),
5253
);
5354

5455
await runtime.idle();
@@ -98,7 +99,7 @@ describe("recipes with HTML", () => {
9899
{ title: "item 2", done: true },
99100
],
100101
},
101-
runtime.documentMap.getDoc(undefined, "todo-list-result", "test")
102+
runtime.documentMap.getDoc(undefined, "todo-list-result", "test"),
102103
);
103104

104105
await runtime.idle();
@@ -140,7 +141,7 @@ describe("recipes with HTML", () => {
140141
{ title: "item 2", done: true },
141142
],
142143
},
143-
runtime.documentMap.getDoc(undefined, "nested-todo-result", "test")
144+
runtime.documentMap.getDoc(undefined, "nested-todo-result", "test"),
144145
);
145146

146147
await runtime.idle();
@@ -161,7 +162,7 @@ describe("recipes with HTML", () => {
161162
const result = runtime.run(
162163
strRecipe,
163164
{ name: "world" },
164-
runtime.documentMap.getDoc(undefined, "str-recipe-result", "test")
165+
runtime.documentMap.getDoc(undefined, "str-recipe-result", "test"),
165166
);
166167

167168
await runtime.idle();
@@ -202,7 +203,7 @@ describe("recipes with HTML", () => {
202203
const result = runtime.run(
203204
nestedMapRecipe,
204205
data,
205-
runtime.documentMap.getDoc(undefined, "nested-map-result", "test")
206+
runtime.documentMap.getDoc(undefined, "nested-map-result", "test"),
206207
);
207208

208209
await runtime.idle();

packages/runner/src/harness/local-build.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import ts from "typescript";
22
import { RawSourceMap, SourceMapConsumer } from "source-map-js";
33
import * as commonHtml from "@commontools/html";
4-
import * as commonBuilder from "@commontools/builder";
5-
import { createBuilder } from "@commontools/builder";
6-
import { getCellLinkOrThrow } from "../query-result-proxy.ts";
74
import * as zod from "zod";
85
import * as zodToJsonSchema from "zod-to-json-schema";
96
import * as merkleReference from "merkle-reference";
107
import turndown from "turndown";
8+
import { createBuilder } from "@commontools/builder";
119
import { type IRuntime } from "../runtime.ts";
1210

1311
let DOMParser: any;
@@ -210,6 +208,7 @@ export const tsToExports = async (
210208
case "@commontools/html":
211209
return commonHtml;
212210
case "@commontools/builder":
211+
case "@commontools/builder/interface":
213212
return createBuilder(config.runtime);
214213
case "zod":
215214
return zod;

packages/runner/test/recipes.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {
44
type Cell,
55
createBuilder,
66
type JSONSchema,
7-
TYPE,
87
} from "@commontools/builder";
98
import { Runtime } from "../src/runtime.ts";
109
import { type ErrorWithContext } from "../src/scheduler.ts";
@@ -18,6 +17,7 @@ describe("Recipe Runner", () => {
1817
let createCell: ReturnType<typeof createBuilder>["createCell"];
1918
let handler: ReturnType<typeof createBuilder>["handler"];
2019
let byRef: ReturnType<typeof createBuilder>["byRef"];
20+
let TYPE: ReturnType<typeof createBuilder>["TYPE"];
2121

2222
beforeEach(() => {
2323
runtime = new Runtime({
@@ -30,6 +30,7 @@ describe("Recipe Runner", () => {
3030
createCell,
3131
handler,
3232
byRef,
33+
TYPE,
3334
} = builder);
3435
});
3536

packages/runner/test/schema-lineage.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ import {
44
type Cell,
55
createBuilder,
66
type JSONSchema,
7-
UI,
87
} from "@commontools/builder";
98
import { isCell } from "../src/cell.ts";
109
import { Runtime } from "../src/runtime.ts";
1110

1211
describe("Schema Lineage", () => {
1312
let runtime: Runtime;
1413
let recipe: ReturnType<typeof createBuilder>["recipe"];
14+
let UI: ReturnType<typeof createBuilder>["UI"];
1515

1616
beforeEach(() => {
1717
runtime = new Runtime({
1818
storageUrl: "volatile://",
1919
});
2020
const builder = createBuilder(runtime);
21-
({ recipe } = builder);
21+
({ recipe, UI } = builder);
2222
});
2323

2424
afterEach(async () => {
@@ -234,13 +234,14 @@ describe("Schema Lineage", () => {
234234
describe("Schema propagation end-to-end example", () => {
235235
let runtime: Runtime;
236236
let recipe: ReturnType<typeof createBuilder>["recipe"];
237+
let UI: ReturnType<typeof createBuilder>["UI"];
237238

238239
beforeEach(() => {
239240
runtime = new Runtime({
240241
storageUrl: "volatile://",
241242
});
242243
const builder = createBuilder(runtime);
243-
({ recipe } = builder);
244+
({ recipe, UI } = builder);
244245
});
245246

246247
afterEach(async () => {

0 commit comments

Comments
 (0)