Skip to content

Commit 053fdc1

Browse files
committed
chore(api): Move runtime constant definitions from @commontools/api to @commontools/runner
Changed ID, ID_FIELD, TYPE, NAME, and UI from concrete exports to ambient declarations in @commontools/api, getting it closer to being a pure TypeScript interface package. The actual runtime values are now defined in @commontools/runner/src/builder/types.ts, where the runtime environment is created. Type compatibility is maintained by having the runner reference the API's declared types using typeof, ensuring both locations share the same TypeScript symbol types. Non-pattern code like tests or Lit components should import the types from @commontools/runner instead of @commontools/api
1 parent 991fb20 commit 053fdc1

File tree

4 files changed

+26
-30
lines changed

4 files changed

+26
-30
lines changed

packages/api/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@
55
* Workspace code should import these types via `@commontools/builder`.
66
*/
77

8-
export const ID: unique symbol = Symbol("ID, unique to the context");
9-
export const ID_FIELD: unique symbol = Symbol(
10-
"ID_FIELD, name of sibling that contains id",
11-
);
8+
// Runtime constants - defined by @commontools/runner/src/builder/types.ts
9+
// These are ambient declarations since the actual values are provided by the runtime environment
10+
export declare const ID: unique symbol;
11+
export declare const ID_FIELD: unique symbol;
1212

1313
// Should be Symbol("UI") or so, but this makes repeat() use these when
1414
// iterating over recipes.
15-
export const TYPE = "$TYPE";
16-
export const NAME = "$NAME";
17-
export const UI = "$UI";
15+
export declare const TYPE: "$TYPE";
16+
export declare const NAME: "$NAME";
17+
export declare const UI: "$UI";
1818

1919
// ============================================================================
2020
// Cell Brand System

packages/html/test/render.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { beforeEach, describe, it } from "@std/testing/bdd";
2-
import { h, UI, VNode } from "@commontools/api";
2+
import { h, UI, VNode } from "@commontools/runner";
33
import { render, renderImpl } from "../src/render.ts";
44
import * as assert from "./assert.ts";
55
import { serializableEvent } from "../src/render.ts";

packages/runner/src/builder/types.ts

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import type {
1414
GenerateObjectFunction,
1515
GetRecipeEnvironmentFunction,
1616
HandlerFunction,
17+
ID as IDSymbol,
18+
ID_FIELD as IDFieldSymbol,
1719
IfElseFunction,
1820
JSONSchema,
1921
JSONSchemaObj,
@@ -36,29 +38,23 @@ import type {
3638
StrFunction,
3739
WishFunction,
3840
} from "@commontools/api";
39-
import {
40-
h,
41-
ID,
42-
ID_FIELD,
43-
NAME,
44-
schema,
45-
toSchema,
46-
TYPE,
47-
UI,
48-
} from "@commontools/api";
41+
import { h, schema, toSchema } from "@commontools/api";
4942
import { AuthSchema } from "./schema-lib.ts";
43+
44+
// Define runtime constants here - actual runtime values
45+
export const ID: typeof IDSymbol = Symbol("ID, unique to the context") as any;
46+
export const ID_FIELD: typeof IDFieldSymbol = Symbol(
47+
"ID_FIELD, name of sibling that contains id",
48+
) as any;
49+
50+
// Should be Symbol("UI") or so, but this makes repeat() use these when
51+
// iterating over recipes.
52+
export const TYPE = "$TYPE";
53+
export const NAME = "$NAME";
54+
export const UI = "$UI";
55+
5056
export { AuthSchema } from "./schema-lib.ts";
51-
export {
52-
h,
53-
ID,
54-
ID_FIELD,
55-
NAME,
56-
type Schema,
57-
schema,
58-
toSchema,
59-
TYPE,
60-
UI,
61-
} from "@commontools/api";
57+
export { h, type Schema, schema, toSchema } from "@commontools/api";
6258
export type {
6359
AnyCell,
6460
Cell,

packages/ui/src/v2/components/ct-render/ct-render.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { BaseElement } from "../../core/base-element.ts";
33
import { render } from "@commontools/html";
44
import type { Cell } from "@commontools/runner";
55
import { getRecipeIdFromCharm } from "@commontools/charm";
6-
import { UI, type VNode } from "@commontools/api";
6+
import { UI, type VNode } from "@commontools/runner";
77

88
// Set to true to enable debug logging
99
const DEBUG_LOGGING = false;

0 commit comments

Comments
 (0)