From d4bf16fd030cac02791f10efe3f37852886d86b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20Xalambr=C3=AD?= Date: Sat, 9 Dec 2023 01:06:25 -0500 Subject: [PATCH] Remove entities code --- app/entities/bookmark.ts | 12 -------- app/entities/date-time.ts | 7 ----- app/entities/markdown.ts | 63 --------------------------------------- app/entities/note.ts | 52 -------------------------------- app/entities/semver.ts | 6 ---- app/entities/tutorial.ts | 10 ------- 6 files changed, 150 deletions(-) delete mode 100644 app/entities/bookmark.ts delete mode 100644 app/entities/date-time.ts delete mode 100644 app/entities/markdown.ts delete mode 100644 app/entities/note.ts delete mode 100644 app/entities/semver.ts delete mode 100644 app/entities/tutorial.ts diff --git a/app/entities/bookmark.ts b/app/entities/bookmark.ts deleted file mode 100644 index b30dd30..0000000 --- a/app/entities/bookmark.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { z } from "zod"; - -export const BookmarkSchema = z.object({ - id: z.string(), - title: z.string(), - // description: z.string(), - // comment: z.string().nullable(), - url: z.string().url(), - - // Timestamps - created_at: z.string(), -}); diff --git a/app/entities/date-time.ts b/app/entities/date-time.ts deleted file mode 100644 index e485ecd..0000000 --- a/app/entities/date-time.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { z } from "zod"; - -export const DateTimeSchema = z - .string() - .datetime() - .transform((value) => new Date(value)) - .pipe(z.date()); diff --git a/app/entities/markdown.ts b/app/entities/markdown.ts deleted file mode 100644 index 8b46831..0000000 --- a/app/entities/markdown.ts +++ /dev/null @@ -1,63 +0,0 @@ -import type { Scalar, Tag } from "@markdoc/markdoc"; - -import { parse, transform } from "@markdoc/markdoc"; -import { z } from "zod"; - -export const TagSchema: z.ZodType = z.object({ - $$mdtype: z.literal("Tag"), - name: z.string(), - attributes: z.record(z.any()), - children: z.lazy(() => RenderableTreeNodeSchema.array()), -}); - -export const ScalarSchema: z.ZodType = z.union([ - z.null(), - z.boolean(), - z.number(), - z.string(), - z.lazy(() => ScalarSchema.array()), - z.record(z.lazy(() => ScalarSchema)), -]); - -export const RenderableTreeNodeSchema = z.union([TagSchema, ScalarSchema]); - -export const MarkdownSchema = z - .string() - .transform((content) => { - if (content.startsWith("# ")) { - let [title, ...body] = content.split("\n"); - - return { - attributes: { - title: title.slice(1).trim(), - tags: [], - }, - body: transform(parse(body.join("\n").trimStart())), - }; - } - - let [tags, ...rest] = content.split("\n"); - let [title, ...body] = rest.join("\n").trim().split("\n"); - - return { - attributes: { - title: title.slice(1).trim(), - tags: tags - .split("#") - .map((tag) => tag.trim()) - .filter(Boolean), - }, - body: transform(parse(body.join("\n").trimStart())), - }; - }) - .pipe( - z.object({ - attributes: z.object({ - title: z.string().min(1).max(140), - tags: z.string().array(), - }), - body: RenderableTreeNodeSchema, - }), - ); - -export type Markdown = z.infer; diff --git a/app/entities/note.ts b/app/entities/note.ts deleted file mode 100644 index 7ec44f4..0000000 --- a/app/entities/note.ts +++ /dev/null @@ -1,52 +0,0 @@ -import { z } from "zod"; - -const NoteVisibilitySchema = z.union([ - z.literal("public"), - z.literal("private"), - z.literal("public_unlisted"), - z.literal("public_site"), -]); - -export const NoteSchema = z.object({ - id: z.number(), - site_id: z.number(), - user_id: z.number(), - body: z.string(), - path: z.string(), - headline: z.string(), - title: z.string(), - created_at: z.string(), - updated_at: z.string(), - visibility: NoteVisibilitySchema.default("public"), - poster: z.string().nullable(), - curated: z.boolean(), - ordering: z.number(), - url: z.string(), -}); - -const NotesReorderedEventSchema = z.object({ - event: z.literal("notes-reordered"), - data: z.object({ notes: NoteSchema.array() }), -}); - -const NoteUpdatedEventSchema = z.object({ - event: z.literal("note-updated"), - data: z.object({ note: NoteSchema }), -}); - -const NoteCreatedEventSchema = z.object({ - event: z.literal("note-created"), - data: z.object({ note: NoteSchema }), -}); - -const NoteDeletedEventSchema = z.object({ - event: z.literal("note-deleted"), - data: z.object({ note: NoteSchema }), -}); - -export const NoteEventSchema = z.union([ - NotesReorderedEventSchema, - NoteUpdatedEventSchema, - NoteCreatedEventSchema, - NoteDeletedEventSchema, -]); diff --git a/app/entities/semver.ts b/app/entities/semver.ts deleted file mode 100644 index 9c6ea1a..0000000 --- a/app/entities/semver.ts +++ /dev/null @@ -1,6 +0,0 @@ -import * as semver from "semver"; -import { z } from "zod"; - -export const SemanticVersionSchema = z - .string() - .refine((value) => semver.valid(value), { message: "INVALID_VERSION" }); diff --git a/app/entities/tutorial.ts b/app/entities/tutorial.ts deleted file mode 100644 index 4dd841a..0000000 --- a/app/entities/tutorial.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { z } from "zod"; - -import { RenderableTreeNodeSchema } from "~/entities/markdown"; - -export const TutorialSchema = z.object({ - content: RenderableTreeNodeSchema, - slug: z.string(), - tags: z.string().array(), - title: z.string(), -});