@duckpic/content-spec 0.2.3 → 0.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export const VocabularyListPropsSchema = z.object({
|
|
3
3
|
title: z.string().optional(),
|
|
4
|
-
staticVocabIds: z.array(z.number())
|
|
4
|
+
staticVocabIds: z.array(z.number())
|
|
5
5
|
});
|
|
6
6
|
export const VocabularyListComponentSpec = {
|
|
7
7
|
type: "VocabularyList",
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@ import type { ComponentSpec } from "./ComponentSpec";
|
|
|
3
3
|
|
|
4
4
|
export const VocabularyListPropsSchema = z.object({
|
|
5
5
|
title: z.string().optional(),
|
|
6
|
-
staticVocabIds: z.array(z.number())
|
|
6
|
+
staticVocabIds: z.array(z.number())
|
|
7
7
|
});
|
|
8
8
|
|
|
9
9
|
export const VocabularyListComponentSpec: ComponentSpec = {
|
package/dist/files.txt
DELETED
|
@@ -1,265 +0,0 @@
|
|
|
1
|
-
--components/ComponentSpec.d.ts--
|
|
2
|
-
import type { ZodType } from "zod";
|
|
3
|
-
export interface ComponentSpec {
|
|
4
|
-
type: string;
|
|
5
|
-
propsSchema: ZodType<any>;
|
|
6
|
-
slots: string[];
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
--components/ComponentSpec.js--
|
|
11
|
-
export {};
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
--components/Layout.d.ts--
|
|
15
|
-
import { z } from "zod";
|
|
16
|
-
import type { ComponentSpec } from "./ComponentSpec";
|
|
17
|
-
export declare const LayoutPropsSchema: z.ZodObject<{
|
|
18
|
-
backgroundColor: z.ZodOptional<z.ZodString>;
|
|
19
|
-
style: z.ZodOptional<z.ZodObject<{
|
|
20
|
-
backgroundColor: z.ZodOptional<z.ZodString>;
|
|
21
|
-
padding: z.ZodOptional<z.ZodString>;
|
|
22
|
-
borderRadius: z.ZodOptional<z.ZodString>;
|
|
23
|
-
}, z.core.$strip>>;
|
|
24
|
-
}, z.core.$strip>;
|
|
25
|
-
export declare const LayoutComponentSpec: ComponentSpec;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
--components/Layout.js--
|
|
29
|
-
import { z } from "zod";
|
|
30
|
-
export const LayoutPropsSchema = z.object({
|
|
31
|
-
backgroundColor: z.string().optional(),
|
|
32
|
-
style: z.object({
|
|
33
|
-
backgroundColor: z.string().optional(),
|
|
34
|
-
padding: z.string().optional(),
|
|
35
|
-
borderRadius: z.string().optional()
|
|
36
|
-
}).optional()
|
|
37
|
-
});
|
|
38
|
-
export const LayoutComponentSpec = {
|
|
39
|
-
type: "Layout",
|
|
40
|
-
propsSchema: LayoutPropsSchema,
|
|
41
|
-
slots: ["content"]
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
--components/Page.d.ts--
|
|
46
|
-
import { z } from "zod";
|
|
47
|
-
import type { ComponentSpec } from "./ComponentSpec";
|
|
48
|
-
export declare const PagePropsSchema: z.ZodObject<{
|
|
49
|
-
title: z.ZodOptional<z.ZodString>;
|
|
50
|
-
backgroundColor: z.ZodOptional<z.ZodString>;
|
|
51
|
-
}, z.core.$strip>;
|
|
52
|
-
export declare const PageComponentSpec: ComponentSpec;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
--components/Page.js--
|
|
56
|
-
import { z } from "zod";
|
|
57
|
-
export const PagePropsSchema = z.object({
|
|
58
|
-
title: z.string().optional(),
|
|
59
|
-
backgroundColor: z.string().optional()
|
|
60
|
-
});
|
|
61
|
-
export const PageComponentSpec = {
|
|
62
|
-
type: "Page",
|
|
63
|
-
propsSchema: PagePropsSchema,
|
|
64
|
-
slots: ["main"]
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
--components/Quiz.d.ts--
|
|
69
|
-
import { z } from "zod";
|
|
70
|
-
import { ComponentSpec } from "./ComponentSpec";
|
|
71
|
-
export declare const QuizQuestionSchema: z.ZodObject<{
|
|
72
|
-
q: z.ZodString;
|
|
73
|
-
a: z.ZodString;
|
|
74
|
-
}, z.core.$strip>;
|
|
75
|
-
export declare const QuizPropsSchema: z.ZodObject<{
|
|
76
|
-
title: z.ZodOptional<z.ZodString>;
|
|
77
|
-
questions: z.ZodArray<z.ZodObject<{
|
|
78
|
-
q: z.ZodString;
|
|
79
|
-
a: z.ZodString;
|
|
80
|
-
}, z.core.$strip>>;
|
|
81
|
-
backgroundColor: z.ZodOptional<z.ZodString>;
|
|
82
|
-
}, z.core.$strip>;
|
|
83
|
-
export type QuizProps = z.infer<typeof QuizPropsSchema>;
|
|
84
|
-
export declare const QuizComponentSpec: ComponentSpec;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
--components/Quiz.js--
|
|
88
|
-
import { z } from "zod";
|
|
89
|
-
export const QuizQuestionSchema = z.object({
|
|
90
|
-
q: z.string(),
|
|
91
|
-
a: z.string()
|
|
92
|
-
});
|
|
93
|
-
export const QuizPropsSchema = z.object({
|
|
94
|
-
title: z.string().optional(),
|
|
95
|
-
questions: z.array(QuizQuestionSchema).min(1),
|
|
96
|
-
backgroundColor: z.string().optional()
|
|
97
|
-
});
|
|
98
|
-
export const QuizComponentSpec = {
|
|
99
|
-
type: "Quiz",
|
|
100
|
-
propsSchema: QuizPropsSchema,
|
|
101
|
-
slots: [] // quizzes don’t have child nodes
|
|
102
|
-
};
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
--components/Text.d.ts--
|
|
106
|
-
import { z } from "zod";
|
|
107
|
-
import type { ComponentSpec } from "./ComponentSpec";
|
|
108
|
-
export declare const TextPropsSchema: z.ZodObject<{
|
|
109
|
-
variant: z.ZodEnum<{
|
|
110
|
-
body: "body";
|
|
111
|
-
h1: "h1";
|
|
112
|
-
h2: "h2";
|
|
113
|
-
h3: "h3";
|
|
114
|
-
}>;
|
|
115
|
-
text: z.ZodString;
|
|
116
|
-
backgroundColor: z.ZodOptional<z.ZodString>;
|
|
117
|
-
}, z.core.$strip>;
|
|
118
|
-
export declare const TextComponentSpec: ComponentSpec;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
--components/Text.js--
|
|
122
|
-
import { z } from "zod";
|
|
123
|
-
export const TextPropsSchema = z.object({
|
|
124
|
-
variant: z.enum(["h1", "h2", "h3", "body"]),
|
|
125
|
-
text: z.string(),
|
|
126
|
-
backgroundColor: z.string().optional()
|
|
127
|
-
});
|
|
128
|
-
export const TextComponentSpec = {
|
|
129
|
-
type: "Text",
|
|
130
|
-
propsSchema: TextPropsSchema,
|
|
131
|
-
slots: []
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
--index.d.ts--
|
|
136
|
-
export * from "./components/Text";
|
|
137
|
-
export * from "./components/Quiz";
|
|
138
|
-
export * from "./components/Layout";
|
|
139
|
-
export * from "./components/Page";
|
|
140
|
-
export * from "./schema/PageTree";
|
|
141
|
-
import type { ComponentSpec } from "./components/ComponentSpec.ts";
|
|
142
|
-
export declare const ComponentRegistry: {
|
|
143
|
-
Text: ComponentSpec;
|
|
144
|
-
Quiz: ComponentSpec;
|
|
145
|
-
Layout: ComponentSpec;
|
|
146
|
-
Page: ComponentSpec;
|
|
147
|
-
};
|
|
148
|
-
export type ComponentType = keyof typeof ComponentRegistry;
|
|
149
|
-
export declare function getPropsSchema(type: ComponentType): import("zod").ZodType<any, unknown, import("zod/v4/core").$ZodTypeInternals<any, unknown>>;
|
|
150
|
-
export type { ComponentSpec };
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
--index.js--
|
|
154
|
-
export * from "./components/Text";
|
|
155
|
-
export * from "./components/Quiz";
|
|
156
|
-
export * from "./components/Layout";
|
|
157
|
-
export * from "./components/Page";
|
|
158
|
-
export * from "./schema/PageTree";
|
|
159
|
-
import { TextComponentSpec } from "./components/Text";
|
|
160
|
-
import { QuizComponentSpec } from "./components/Quiz";
|
|
161
|
-
import { LayoutComponentSpec } from "./components/Layout";
|
|
162
|
-
import { PageComponentSpec } from "./components/Page";
|
|
163
|
-
export const ComponentRegistry = {
|
|
164
|
-
Text: TextComponentSpec,
|
|
165
|
-
Quiz: QuizComponentSpec,
|
|
166
|
-
Layout: LayoutComponentSpec,
|
|
167
|
-
Page: PageComponentSpec
|
|
168
|
-
};
|
|
169
|
-
// Helper to get a schema by type
|
|
170
|
-
export function getPropsSchema(type) {
|
|
171
|
-
return ComponentRegistry[type].propsSchema;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
--schema/PageTree.d.ts--
|
|
176
|
-
import { z } from "zod";
|
|
177
|
-
export declare const NodeIdSchema: z.ZodString;
|
|
178
|
-
export declare const ContentNodeSchema: z.ZodObject<{
|
|
179
|
-
id: z.ZodString;
|
|
180
|
-
type: z.ZodString;
|
|
181
|
-
props: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
182
|
-
slots: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
|
|
183
|
-
}, z.core.$strip>;
|
|
184
|
-
export type ContentNode = z.infer<typeof ContentNodeSchema>;
|
|
185
|
-
export declare const PageTreeSchema: z.ZodObject<{
|
|
186
|
-
version: z.ZodString;
|
|
187
|
-
root: z.ZodString;
|
|
188
|
-
nodes: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
189
|
-
id: z.ZodString;
|
|
190
|
-
type: z.ZodString;
|
|
191
|
-
props: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
192
|
-
slots: z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>;
|
|
193
|
-
}, z.core.$strip>>;
|
|
194
|
-
}, z.core.$strip>;
|
|
195
|
-
export type PageTree = z.infer<typeof PageTreeSchema>;
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
--schema/PageTree.js--
|
|
199
|
-
import { z } from "zod";
|
|
200
|
-
export const NodeIdSchema = z.string().min(1);
|
|
201
|
-
// You can switch to stricter UUID validation later.
|
|
202
|
-
export const ContentNodeSchema = z.object({
|
|
203
|
-
id: NodeIdSchema,
|
|
204
|
-
type: z.string(), // we'll refine typing later
|
|
205
|
-
props: z.record(z.string(), z.any()), // key: string, value: any
|
|
206
|
-
slots: z.record(z.string(), z.array(NodeIdSchema))
|
|
207
|
-
});
|
|
208
|
-
export const PageTreeSchema = z.object({
|
|
209
|
-
version: z.string(),
|
|
210
|
-
root: NodeIdSchema,
|
|
211
|
-
nodes: z.record(z.string(), ContentNodeSchema)
|
|
212
|
-
});
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
--validators/validateNode.d.ts--
|
|
216
|
-
import { ContentNode } from "..";
|
|
217
|
-
export declare function validateNode(node: ContentNode): void;
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
--validators/validateNode.js--
|
|
221
|
-
import { ComponentRegistry } from "..";
|
|
222
|
-
export function validateNode(node) {
|
|
223
|
-
const type = node.type;
|
|
224
|
-
const spec = ComponentRegistry[type];
|
|
225
|
-
if (!spec) {
|
|
226
|
-
throw new Error(`Unknown component type: ${node.type}`);
|
|
227
|
-
}
|
|
228
|
-
// 1) Validate props
|
|
229
|
-
spec.propsSchema.parse(node.props);
|
|
230
|
-
// 2) Validate slots
|
|
231
|
-
const allowedSlots = (spec.slots ?? []);
|
|
232
|
-
for (const slotName of Object.keys(node.slots)) {
|
|
233
|
-
if (!allowedSlots.includes(slotName)) {
|
|
234
|
-
throw new Error(`Invalid slot '${slotName}' for component type ${node.type}`);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
--validators/validatePageTree.d.ts--
|
|
241
|
-
export declare function validatePageTree(tree: unknown): {
|
|
242
|
-
version: string;
|
|
243
|
-
root: string;
|
|
244
|
-
nodes: Record<string, {
|
|
245
|
-
id: string;
|
|
246
|
-
type: string;
|
|
247
|
-
props: Record<string, any>;
|
|
248
|
-
slots: Record<string, string[]>;
|
|
249
|
-
}>;
|
|
250
|
-
};
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
--validators/validatePageTree.js--
|
|
254
|
-
import { PageTreeSchema } from "../schema/PageTree";
|
|
255
|
-
import { validateNode } from "./validateNode";
|
|
256
|
-
export function validatePageTree(tree) {
|
|
257
|
-
const data = PageTreeSchema.parse(tree); // main shape
|
|
258
|
-
// Validate nodes individually
|
|
259
|
-
for (const node of Object.values(data.nodes)) {
|
|
260
|
-
validateNode(node);
|
|
261
|
-
}
|
|
262
|
-
return data;
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
|