Skip to content

Commit 59e6ce9

Browse files
Copilothotlong
andcommitted
Address code review feedback: improve types, comments, and naming
Co-authored-by: hotlong <50353452+hotlong@users.noreply.github.com>
1 parent c49153d commit 59e6ce9

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

apps/console/objectstack.shared.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,9 @@ export const sharedConfig = {
102102
const allConfigs = [crmConfig, todoConfig, kitchenSinkConfig];
103103

104104
// defineStack() validates the config but strips non-standard properties like
105-
// listViews and actions from objects. Re-compose after validation so the
106-
// runtime protocol serves objects with their view and action definitions.
105+
// listViews and actions from objects. A second composeStacks pass restores
106+
// these runtime properties onto the validated objects. This double-pass is
107+
// necessary because defineStack's Zod schema doesn't preserve custom fields.
107108
const validated = defineStack(sharedConfig as Parameters<typeof defineStack>[0]);
108109
export default {
109110
...validated,

objectstack.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ const mergedApp = defineStack({
5858
pages: composed.pages,
5959
} as any);
6060

61-
// Re-compose after defineStack validation to restore listViews and actions
61+
// defineStack() validates the config but strips non-standard properties like
62+
// listViews and actions from objects. A second composeStacks pass restores
63+
// these runtime properties onto the validated objects. This double-pass is
64+
// necessary because defineStack's Zod schema doesn't preserve custom fields.
6265
const mergedAppWithViews = {
6366
...mergedApp,
6467
objects: composeStacks([

packages/core/src/utils/compose-stacks.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,19 @@
1111
* - Handles duplicate object names via `objectConflict` option
1212
* - Merges stack-level views (listViews) into corresponding objects
1313
* - Merges stack-level actions into objects via explicit `objectName` field
14+
*
15+
* Note: Uses Record<string, any> because inputs can be raw defineStack output,
16+
* plugin getConfig() results, or partial stacks with only views/actions.
1417
*/
1518

1619
export interface ComposeStacksOptions {
1720
/** How to resolve two objects with the same `name`. Default: 'override' (last wins). */
1821
objectConflict?: 'override' | 'error';
1922
}
2023

24+
/** A partial or full stack definition used as input to composeStacks. */
25+
export type StackInput = Record<string, any>;
26+
2127
/**
2228
* Compose multiple stack definitions into a single merged definition.
2329
*
@@ -26,7 +32,7 @@ export interface ComposeStacksOptions {
2632
* @returns A merged stack definition (unvalidated — call defineStack if needed)
2733
*/
2834
export function composeStacks(
29-
stacks: Record<string, any>[],
35+
stacks: StackInput[],
3036
options: ComposeStacksOptions = {},
3137
): Record<string, any> {
3238
const { objectConflict = 'override' } = options;
@@ -57,7 +63,7 @@ export function composeStacks(
5763
for (const obj of allObjects) {
5864
const name = obj?.name;
5965
if (!name) {
60-
objectMap.set(`__anon_${objectMap.size}`, obj);
66+
objectMap.set(`__unnamed_${objectMap.size}`, obj);
6167
continue;
6268
}
6369
if (objectMap.has(name)) {

0 commit comments

Comments
 (0)