Skip to content

Commit 2f4b3a9

Browse files
committed
fix(schema): detect extra fields in nested field
1 parent 3090a5e commit 2f4b3a9

File tree

6 files changed

+137
-116
lines changed

6 files changed

+137
-116
lines changed

schema/airesponses.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const schema = z
3131
completionTokens: z.number().optional(),
3232
totalTokens: z.number().optional(),
3333
})
34+
.strict()
3435
.optional(),
3536

3637
createdAt: dateSchema,

schema/analytics.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,28 @@ export const schema = z
1414
// the timestamp for when the data is fetched
1515
fetchedAt: dateSchema,
1616

17-
stats: z.object({
18-
lineUser: z.number().nullable().optional(),
19-
lineVisit: z.number().nullable().optional(),
20-
webUser: z.number().nullable().optional(),
21-
webVisit: z.number().nullable().optional(),
22-
23-
/** LIFF traffic, breakdown by source */
24-
liff: z
25-
.array(
26-
z.object({
27-
// Source can be '' or null if not specified
28-
source: z.string().nullable(),
29-
user: z.number(),
30-
visit: z.number(),
31-
})
32-
)
33-
.optional(),
34-
}),
17+
stats: z
18+
.object({
19+
lineUser: z.number().nullable().optional(),
20+
lineVisit: z.number().nullable().optional(),
21+
webUser: z.number().nullable().optional(),
22+
webVisit: z.number().nullable().optional(),
23+
24+
/** LIFF traffic, breakdown by source */
25+
liff: z
26+
.array(
27+
z
28+
.object({
29+
// Source can be '' or null if not specified
30+
source: z.string().nullable(),
31+
user: z.number(),
32+
visit: z.number(),
33+
})
34+
.strict()
35+
)
36+
.optional(),
37+
})
38+
.strict(),
3539

3640
type: z.enum(['article', 'reply']),
3741

schema/articles.ts

Lines changed: 79 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,43 @@ export const schema = z
2121
* "references" field should be a list of such occurrences.
2222
*/
2323
references: z.array(
24-
z.object({
25-
type: z.string(), // LINE, URL, etc
26-
permalink: z.string().optional(), // permalink to the resource if applicable
27-
createdAt: dateSchema.optional().nullable(),
28-
29-
// auth
30-
userId: z.string().optional(),
31-
appId: z.string().optional(),
32-
})
24+
z
25+
.object({
26+
type: z.string(), // LINE, URL, etc
27+
permalink: z.string().optional(), // permalink to the resource if applicable
28+
createdAt: dateSchema.optional().nullable(),
29+
30+
// auth
31+
userId: z.string().optional(),
32+
appId: z.string().optional(),
33+
})
34+
.strict()
3335
),
3436

3537
/** Linkage between articles and replies */
3638
articleReplies: z.array(
37-
z.object({
38-
/** Who connected the replyId with the article. */
39-
userId: z.string(),
40-
appId: z.string(),
41-
42-
/** Counter cache for feedbacks */
43-
positiveFeedbackCount: z.number(),
44-
negativeFeedbackCount: z.number(),
45-
46-
/** One reply can have multiple articlereplies. */
47-
replyId: z.string(),
48-
49-
/** Current reply type */
50-
replyType: z.string(),
51-
52-
status: z.enum(['NORMAL', 'DELETED', 'BLOCKED']),
53-
/** Can be null for very old replies */
54-
createdAt: dateSchema.nullable(),
55-
updatedAt: dateSchema.optional().nullable(),
56-
})
39+
z
40+
.object({
41+
/** Who connected the replyId with the article. */
42+
userId: z.string(),
43+
appId: z.string(),
44+
45+
/** Counter cache for feedbacks */
46+
positiveFeedbackCount: z.number(),
47+
negativeFeedbackCount: z.number(),
48+
49+
/** One reply can have multiple articlereplies. */
50+
replyId: z.string(),
51+
52+
/** Current reply type */
53+
replyType: z.string(),
54+
55+
status: z.enum(['NORMAL', 'DELETED', 'BLOCKED']),
56+
/** Can be null for very old replies */
57+
createdAt: dateSchema.nullable(),
58+
updatedAt: dateSchema.optional().nullable(),
59+
})
60+
.strict()
5761
),
5862

5963
/**
@@ -70,44 +74,48 @@ export const schema = z
7074
/** Links in article text */
7175
hyperlinks: z
7276
.array(
73-
z.object({
74-
/** exact URL found in the articles */
75-
url: z.string(),
76-
77-
/** URL after normalization (stored in urls) */
78-
normalizedUrl: z.string().optional(),
79-
title: z.string().nullable(),
80-
81-
/** Extracted summary text */
82-
summary: z.string().optional().nullable(),
83-
})
77+
z
78+
.object({
79+
/** exact URL found in the articles */
80+
url: z.string(),
81+
82+
/** URL after normalization (stored in urls) */
83+
normalizedUrl: z.string().optional(),
84+
title: z.string().nullable(),
85+
86+
/** Extracted summary text */
87+
summary: z.string().optional().nullable(),
88+
})
89+
.strict()
8490
)
8591
.optional(),
8692

8793
articleCategories: z.array(
88-
z.object({
89-
/**
90-
* Who created the category
91-
* Empty if the category is added by AI
92-
*/
93-
userId: z.string().optional(),
94-
appId: z.string().optional(),
95-
96-
/** exists only for AI tags */
97-
aiModel: z.string().optional(),
98-
aiConfidence: z.number().optional(),
99-
100-
/** Counter cache for feedbacks */
101-
positiveFeedbackCount: z.number(),
102-
negativeFeedbackCount: z.number(),
103-
104-
/** Foreign key */
105-
categoryId: z.string(),
106-
107-
status: z.enum(['NORMAL', 'DELETED', 'BLOCKED']),
108-
createdAt: dateSchema,
109-
updatedAt: dateSchema.optional(),
110-
})
94+
z
95+
.object({
96+
/**
97+
* Who created the category
98+
* Empty if the category is added by AI
99+
*/
100+
userId: z.string().optional(),
101+
appId: z.string().optional(),
102+
103+
/** exists only for AI tags */
104+
aiModel: z.string().optional(),
105+
aiConfidence: z.number().optional(),
106+
107+
/** Counter cache for feedbacks */
108+
positiveFeedbackCount: z.number(),
109+
negativeFeedbackCount: z.number(),
110+
111+
/** Foreign key */
112+
categoryId: z.string(),
113+
114+
status: z.enum(['NORMAL', 'DELETED', 'BLOCKED']),
115+
createdAt: dateSchema,
116+
updatedAt: dateSchema.optional(),
117+
})
118+
.strict()
111119
),
112120

113121
articleType: z.enum(['TEXT', 'IMAGE', 'VIDEO', 'AUDIO']),
@@ -122,12 +130,14 @@ export const schema = z
122130
/** transcript contributors */
123131
contributors: z
124132
.array(
125-
z.object({
126-
userId: z.string(),
127-
appId: z.string(),
128-
/** last contribute time of the user */
129-
updatedAt: dateSchema,
130-
})
133+
z
134+
.object({
135+
userId: z.string(),
136+
appId: z.string(),
137+
/** last contribute time of the user */
138+
updatedAt: dateSchema,
139+
})
140+
.strict()
131141
)
132142
.optional(),
133143
})

schema/replies.ts

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,19 @@ export const schema = z
1717
/** Links in article text */
1818
hyperlinks: z
1919
.array(
20-
z.object({
21-
/** exact URL found in the articles */
22-
url: z.string(),
20+
z
21+
.object({
22+
/** exact URL found in the articles */
23+
url: z.string(),
2324

24-
/** URL after normalization (stored in urls) */
25-
normalizedUrl: z.string().optional(),
26-
title: z.string().nullable(),
25+
/** URL after normalization (stored in urls) */
26+
normalizedUrl: z.string().optional(),
27+
title: z.string().nullable(),
2728

28-
/** Extracted summary text */
29-
summary: z.string().optional().nullable(),
30-
})
29+
/** Extracted summary text */
30+
summary: z.string().optional().nullable(),
31+
})
32+
.strict()
3133
)
3234
.optional(),
3335
})

schema/replyrequests.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,22 @@ export const schema = z
3636
*/
3737
feedbacks: z
3838
.array(
39-
z.object({
40-
/**
41-
* Auth
42-
*/
43-
userId: z.string(),
44-
appId: z.string(),
45-
46-
/**
47-
* The score of the feedback. Should be 1, 0, or -1.
48-
*/
49-
score: z.number().int().min(-1).max(1),
50-
createdAt: dateSchema,
51-
updatedAt: dateSchema,
52-
})
39+
z
40+
.object({
41+
/**
42+
* Auth
43+
*/
44+
userId: z.string(),
45+
appId: z.string(),
46+
47+
/**
48+
* The score of the feedback. Should be 1, 0, or -1.
49+
*/
50+
score: z.number().int().min(-1).max(1),
51+
createdAt: dateSchema,
52+
updatedAt: dateSchema,
53+
})
54+
.strict()
5355
)
5456
.optional(),
5557

schema/ydocs.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ export const schema = z
1212
ydoc: z.string(),
1313
versions: z
1414
.array(
15-
z.object({
16-
/** Snapshot of the ydoc in binary format. */
17-
snapshot: z.string(),
18-
/** The creation date of the snapshot. */
19-
createdAt: dateSchema,
20-
})
15+
z
16+
.object({
17+
/** Snapshot of the ydoc in binary format. */
18+
snapshot: z.string(),
19+
/** The creation date of the snapshot. */
20+
createdAt: dateSchema,
21+
})
22+
.strict()
2123
)
2224
.optional(),
2325
})

0 commit comments

Comments
 (0)