Skip to content

Commit

Permalink
#79 extracted ISO Datetime zod parser into a utility module shared ac…
Browse files Browse the repository at this point in the history
…ross crawlers and http functions
  • Loading branch information
fcamblor committed Mar 28, 2024
1 parent 1cc6f71 commit 84c77eb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
3 changes: 2 additions & 1 deletion cloud/functions/src/crawlers/bdxio/crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ import {
BREAK_PARSER,
BREAK_TIME_SLOT_PARSER,
DAY_PARSER,
EVENT_DESCRIPTOR_PARSER, ISO_DATETIME_PARSER, SPEAKER_PARSER
EVENT_DESCRIPTOR_PARSER, SPEAKER_PARSER
} from "../crawler-parsers";
import {CrawlerKind} from "../crawl";
import {ISODatetime} from "../../../../../shared/type-utils";
import {Temporal} from "@js-temporal/polyfill";
import {match, P} from "ts-pattern";
import {http} from "../utils";
import {ISO_DATETIME_PARSER} from "../../utils/zod-parsers";

/**
* WARNING: THIS IS AN AWFUL CRAWLER IMPL
Expand Down
2 changes: 1 addition & 1 deletion cloud/functions/src/crawlers/codeurs-en-seine/crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
BREAK_TIME_SLOT_PARSER,
DAY_PARSER,
EVENT_DESCRIPTOR_PARSER,
ISO_DATETIME_PARSER,
SPEAKER_PARSER,
TALK_FORMAT_PARSER,
THEMABLE_TALK_FORMAT_PARSER
Expand All @@ -21,6 +20,7 @@ import {ISODatetime, ISOLocalDate, Replace} from "../../../../../shared/type-uti
import {Temporal} from "@js-temporal/polyfill";
import {match, P} from "ts-pattern";
import {GithubMDXCrawler} from "../github/GithubMDXCrawler";
import {ISO_DATETIME_PARSER} from "../../utils/zod-parsers";

export const CODEURS_EN_SEINE_PARSER = EVENT_DESCRIPTOR_PARSER.omit({
id: true,
Expand Down
4 changes: 2 additions & 2 deletions cloud/functions/src/crawlers/crawler-parsers.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {z, ZodLiteral} from "zod";
import {ISODatetime, ISOLocalDate, SocialMediaType} from "../../../../shared/type-utils";
import {ISOLocalDate} from "../../../../shared/type-utils";
import {ConferenceDescriptor} from "../../../../shared/conference-descriptor.firestore";
import {ScheduleTimeSlot} from "../../../../shared/daily-schedule.firestore";
import {ISO_DATETIME_PARSER} from "../utils/zod-parsers";


export const HEX_COLOR_PARSER = z.string().regex(/#[0-9a-fA-F]{6}/gi) as unknown as ZodLiteral<`#${string}`>
export const DURATION_PARSER = z.string().regex(/PT\d+m/gi) as unknown as ZodLiteral<`PT${number}m`>
export const ISO_LOCAL_DATE_PARSER = z.string().regex(/\d{4}-\d{2}-\d{2}/gi) as unknown as ZodLiteral<ISOLocalDate>
export const ISO_DATETIME_PARSER = z.string().regex(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?(?:Z|(?:[+-]\d{2}:\d{2}))/gi) as unknown as ZodLiteral<ISODatetime>
export const TIMESLOT_ID_PARSER = z.string()
.regex(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?(?:Z|(?:[+-]\d{2}:\d{2}))--\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?(?:Z|(?:[+-]\d{2}:\d{2}))/gi) as unknown as ZodLiteral<ScheduleTimeSlot['id']>

Expand Down
4 changes: 4 additions & 0 deletions cloud/functions/src/utils/zod-parsers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import {z, ZodLiteral} from "zod";
import {ISODatetime} from "../../../../shared/type-utils";

export const ISO_DATETIME_PARSER = z.string().regex(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{3})?(?:Z|(?:[+-]\d{2}:\d{2}))/gi) as unknown as ZodLiteral<ISODatetime>

0 comments on commit 84c77eb

Please sign in to comment.