Skip to content

Commit ea4ccd5

Browse files
committed
address review
1 parent 8aa69b8 commit ea4ccd5

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

apps/roam/src/components/settings/utils/zodSchema.ts

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,18 @@ const booleanWithDefault = (defaultVal: boolean) =>
9595
.optional()
9696
.transform((val) => val ?? defaultVal);
9797

98-
const defaultNodeIndexValue = {
99-
conditions: [],
100-
selections: [],
98+
const defaultNodeIndex = () => ({
99+
conditions: [] as {
100+
type: string;
101+
relation: string;
102+
source: string;
103+
uid: string;
104+
not: boolean;
105+
}[],
106+
selections: [] as { text: string; label: string }[],
101107
custom: "",
102108
returnNode: "node",
103-
};
109+
});
104110

105111
export const DiscourseNodeSchema = z.object({
106112
text: z.string(),
@@ -116,7 +122,9 @@ export const DiscourseNodeSchema = z.object({
116122
})
117123
.nullable()
118124
.optional()
119-
.transform((val) => val ?? { enabled: false, query: defaultNodeIndexValue }),
125+
.transform(
126+
(val) => val ?? { enabled: false, query: defaultNodeIndex() },
127+
),
120128
template: z
121129
.array(RoamNodeSchema)
122130
.nullable()
@@ -130,7 +138,9 @@ export const DiscourseNodeSchema = z.object({
130138
.optional()
131139
.transform((val) => val ?? {}),
132140
overlay: stringWithDefault(""),
133-
index: IndexSchema.nullable().optional().transform((val) => val ?? defaultNodeIndexValue),
141+
index: IndexSchema.nullable()
142+
.optional()
143+
.transform((val) => val ?? defaultNodeIndex()),
134144
suggestiveRules: SuggestiveRulesSchema.default({}),
135145
backedBy: z
136146
.enum(["user", "default", "relation"])

0 commit comments

Comments
 (0)