summaryrefslogtreecommitdiff
path: root/Homework/cs5260/shared/schema
diff options
context:
space:
mode:
authorElizabeth Alexander Hunt <me@liz.coffee>2026-07-02 11:55:17 -0700
committerElizabeth Alexander Hunt <me@liz.coffee>2026-07-02 11:55:17 -0700
commit6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6 (patch)
treeed97e39ec77c5231ffd2c394493e68d00ddac5a4 /Homework/cs5260/shared/schema
downloadmisc-undergrad-6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6.tar.gz
misc-undergrad-6bf4b90c90f15f4ab60833bddf5b5756d1a6b1f6.zip
Diffstat (limited to 'Homework/cs5260/shared/schema')
-rw-r--r--Homework/cs5260/shared/schema/README.md3
-rw-r--r--Homework/cs5260/shared/schema/Widget.ts13
-rw-r--r--Homework/cs5260/shared/schema/WidgetRequest.json44
-rw-r--r--Homework/cs5260/shared/schema/WidgetRequest.ts16
-rw-r--r--Homework/cs5260/shared/schema/index.ts2
5 files changed, 78 insertions, 0 deletions
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=<schema.json> > <schema>.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<typeof Widget>;
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<typeof WidgetRequest>;
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";