clipit-schema 0.1.0
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.
- package/package.json +20 -0
- package/src/index.ts +91 -0
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "clipit-schema",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Shared Zod schema for clip CLI and web app",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/iamrajjoshi/clipit.git"
|
|
8
|
+
},
|
|
9
|
+
"type": "module",
|
|
10
|
+
"exports": "./src/index.ts",
|
|
11
|
+
"files": [
|
|
12
|
+
"src"
|
|
13
|
+
],
|
|
14
|
+
"publishConfig": {
|
|
15
|
+
"access": "public"
|
|
16
|
+
},
|
|
17
|
+
"dependencies": {
|
|
18
|
+
"zod": "^3.25.76"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
|
|
3
|
+
const tagsSchema = z.array(z.string().trim().min(1)).default([]);
|
|
4
|
+
|
|
5
|
+
export const clipKindSchema = z.enum(["link", "tweet", "image", "video", "note"]);
|
|
6
|
+
|
|
7
|
+
export const baseClipFields = {
|
|
8
|
+
clippedAt: z.coerce.date(),
|
|
9
|
+
tags: tagsSchema,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
const slugField = {
|
|
13
|
+
slug: z.string().trim().min(1),
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const tweetAuthorSchema = z.object({
|
|
17
|
+
name: z.string().trim().min(1),
|
|
18
|
+
handle: z.string().trim().min(1),
|
|
19
|
+
avatar: z.string().trim().min(1).optional(),
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const tweetMediaSchema = z.object({
|
|
23
|
+
src: z.string().trim().min(1),
|
|
24
|
+
alt: z.string().trim().min(1).optional(),
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
export const linkClipDataSchema = z.object({
|
|
28
|
+
kind: z.literal("link"),
|
|
29
|
+
...baseClipFields,
|
|
30
|
+
url: z.string().url(),
|
|
31
|
+
title: z.string().trim().min(1),
|
|
32
|
+
description: z.string().trim().min(1).optional(),
|
|
33
|
+
siteName: z.string().trim().min(1).optional(),
|
|
34
|
+
favicon: z.string().trim().min(1).optional(),
|
|
35
|
+
ogImage: z.string().trim().min(1).optional(),
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
export const tweetClipDataSchema = z.object({
|
|
39
|
+
kind: z.literal("tweet"),
|
|
40
|
+
...baseClipFields,
|
|
41
|
+
platform: z.literal("x"),
|
|
42
|
+
url: z.string().url(),
|
|
43
|
+
author: tweetAuthorSchema,
|
|
44
|
+
text: z.string().trim().min(1),
|
|
45
|
+
postedAt: z.coerce.date(),
|
|
46
|
+
media: z.array(tweetMediaSchema).optional(),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const imageClipDataSchema = z.object({
|
|
50
|
+
kind: z.literal("image"),
|
|
51
|
+
...baseClipFields,
|
|
52
|
+
src: z.string().trim().min(1),
|
|
53
|
+
width: z.number().int().positive(),
|
|
54
|
+
height: z.number().int().positive(),
|
|
55
|
+
alt: z.string().trim().min(1).optional(),
|
|
56
|
+
sourceUrl: z.string().url().optional(),
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
export const videoClipDataSchema = z.object({
|
|
60
|
+
kind: z.literal("video"),
|
|
61
|
+
...baseClipFields,
|
|
62
|
+
url: z.string().url(),
|
|
63
|
+
provider: z.enum(["youtube", "vimeo", "other"]),
|
|
64
|
+
title: z.string().trim().min(1),
|
|
65
|
+
channel: z.string().trim().min(1).optional(),
|
|
66
|
+
thumbnail: z.string().trim().min(1).optional(),
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export const noteClipDataSchema = z.object({
|
|
70
|
+
kind: z.literal("note"),
|
|
71
|
+
...baseClipFields,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export const clipDataSchema = z.discriminatedUnion("kind", [
|
|
75
|
+
linkClipDataSchema,
|
|
76
|
+
tweetClipDataSchema,
|
|
77
|
+
imageClipDataSchema,
|
|
78
|
+
videoClipDataSchema,
|
|
79
|
+
noteClipDataSchema,
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
export const clipFrontmatterSchema = z.discriminatedUnion("kind", [
|
|
83
|
+
linkClipDataSchema.extend(slugField),
|
|
84
|
+
tweetClipDataSchema.extend(slugField),
|
|
85
|
+
imageClipDataSchema.extend(slugField),
|
|
86
|
+
videoClipDataSchema.extend(slugField),
|
|
87
|
+
noteClipDataSchema.extend(slugField),
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
export type ClipFrontmatter = z.infer<typeof clipFrontmatterSchema>;
|
|
91
|
+
export type ClipKind = z.infer<typeof clipKindSchema>;
|