From 6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 Mon Sep 17 00:00:00 2001 From: Elizabeth Alexander Hunt Date: Thu, 2 Jul 2026 11:55:17 -0700 Subject: Init --- Homework/cs5260/shared/schema/README.md | 3 ++ Homework/cs5260/shared/schema/Widget.ts | 13 +++++++ Homework/cs5260/shared/schema/WidgetRequest.json | 44 ++++++++++++++++++++++++ Homework/cs5260/shared/schema/WidgetRequest.ts | 16 +++++++++ Homework/cs5260/shared/schema/index.ts | 2 ++ 5 files changed, 78 insertions(+) create mode 100644 Homework/cs5260/shared/schema/README.md create mode 100644 Homework/cs5260/shared/schema/Widget.ts create mode 100644 Homework/cs5260/shared/schema/WidgetRequest.json create mode 100644 Homework/cs5260/shared/schema/WidgetRequest.ts create mode 100644 Homework/cs5260/shared/schema/index.ts (limited to 'Homework/cs5260/shared/schema') diff --git a/Homework/cs5260/shared/schema/README.md b/Homework/cs5260/shared/schema/README.md new file mode 100644 index 0000000..6c5d0a0 --- /dev/null +++ b/Homework/cs5260/shared/schema/README.md @@ -0,0 +1,3 @@ +to compile TypeScript types + +`json-schema-to-zod --source= > .ts` diff --git a/Homework/cs5260/shared/schema/Widget.ts b/Homework/cs5260/shared/schema/Widget.ts new file mode 100644 index 0000000..e7f09d1 --- /dev/null +++ b/Homework/cs5260/shared/schema/Widget.ts @@ -0,0 +1,13 @@ +import { z } from "zod"; + +export const Widget = z.object({ + id: z.string(), + owner: z.string().regex(new RegExp("[A-Za-z ]+")), + label: z.string().optional(), + description: z.string().optional(), + otherAttributes: z + .array(z.object({ name: z.string(), value: z.string() })) + .optional(), +}); + +export type WidgetT = z.infer; diff --git a/Homework/cs5260/shared/schema/WidgetRequest.json b/Homework/cs5260/shared/schema/WidgetRequest.json new file mode 100644 index 0000000..a378949 --- /dev/null +++ b/Homework/cs5260/shared/schema/WidgetRequest.json @@ -0,0 +1,44 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "properties": { + "type": { + "type": "string", + "pattern": "create|delete|update" + }, + "requestId": { + "type": "string" + }, + "widgetId": { + "type": "string" + }, + "owner": { + "type": "string", + "pattern": "[A-Za-z ]+" + }, + "label": { + "type": "string" + }, + "description": { + "type": "string" + }, + "otherAttributes": { + "type": "array", + "items": [ + { + "type": "object", + "properties": { + "name": { + "type": "string" + }, + "value": { + "type": "string" + } + }, + "required": ["name", "value"] + } + ] + } + }, + "required": ["type", "requestId", "widgetId", "owner"] +} diff --git a/Homework/cs5260/shared/schema/WidgetRequest.ts b/Homework/cs5260/shared/schema/WidgetRequest.ts new file mode 100644 index 0000000..11259cf --- /dev/null +++ b/Homework/cs5260/shared/schema/WidgetRequest.ts @@ -0,0 +1,16 @@ +import { z } from "zod"; + +// generated from json-schema-to-zod +export const WidgetRequest = z.object({ + type: z.string().regex(new RegExp("create|delete|update")), + requestId: z.string(), + widgetId: z.string(), + owner: z.string().regex(new RegExp("[A-Za-z ]+")), + label: z.string().optional(), + description: z.string().optional(), + otherAttributes: z + .array(z.object({ name: z.string(), value: z.string() })) + .optional(), +}); + +export type WidgetRequestT = z.infer; diff --git a/Homework/cs5260/shared/schema/index.ts b/Homework/cs5260/shared/schema/index.ts new file mode 100644 index 0000000..44cdfd7 --- /dev/null +++ b/Homework/cs5260/shared/schema/index.ts @@ -0,0 +1,2 @@ +export * from "./WidgetRequest.ts"; +export * from "./Widget"; -- cgit v1.3