-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use zod for backend type schemas
- Loading branch information
Showing
11 changed files
with
119 additions
and
45 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,19 @@ | ||
import { z } from 'zod' | ||
|
||
/** Set by a user */ | ||
export interface PrompterSettings { | ||
fontSize: number // in percentage of viewport height | ||
export type PrompterSettings = z.infer<typeof PrompterSettingsSchema> | ||
|
||
export const PrompterSettingsSchema = z.object({ | ||
fontSize: z.number().min(0).max(100), | ||
|
||
mirrorHorizontally: boolean | ||
mirrorVertically: boolean | ||
mirrorHorizontally: z.boolean(), | ||
mirrorVertically: z.boolean(), | ||
|
||
focusPosition: 'start' | 'center' | 'end' | ||
showFocusPosition: boolean | ||
focusPosition: z.union([z.literal('start'), z.literal('center'), z.literal('end')]), | ||
showFocusPosition: z.boolean(), | ||
|
||
/** Adds padding between the edge of the screen and the text */ | ||
marginHorizontal: number | ||
marginHorizontal: z.number().min(0).max(100), | ||
/** In percentage of viewport height */ | ||
marginVertical: number | ||
} | ||
marginVertical: z.number().min(0).max(100), | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,40 @@ | ||
import { z } from 'zod' | ||
import { ProtectedString } from '../ProtectedString.js' | ||
import { PartId } from './Part.js' | ||
import { SegmentId } from './Segment.js' | ||
import { ZodProtectedString } from './lib.js' | ||
|
||
/** Represents a view of the prompter, is streamed from the viewPort. This is always the last connected viewport. */ | ||
export interface ViewPort { | ||
_id: 'viewport' | ||
export type ViewPort = z.infer<typeof ViewPortSchema> | ||
|
||
/** Defines a position of the viewport */ | ||
export type ViewPortPosition = z.infer<typeof ViewPortPositionSchema> | ||
|
||
export const ViewPortPositionSchema = z.object({ | ||
/** The position of the ViewPort */ | ||
scrollOffset: z.number(), | ||
/** | ||
* The Part which the current offset is calculated from. | ||
* `null` means "top of page" | ||
*/ | ||
scrollOffsetTarget: ZodProtectedString<SegmentId | PartId | TextMarkerId>().nullable(), | ||
}) | ||
|
||
/** TBD, something used to mark places in ScriptContents */ | ||
export type TextMarkerId = ProtectedString<'TextMarkerId', string> | ||
|
||
export const ViewPortSchema = z.object({ | ||
_id: z.literal('viewport'), | ||
/** | ||
* When a ViewPort starts up, it randomizes its instanceId and sends it to the Server. | ||
* If the ViewPorts' instanceId is the "last one" it is in control. | ||
* The ViewPort "in control" will stream its data to the server continuously. | ||
* If a ViewPort is not "in control" it could listen to the ViewPort data and jump to the same position to stay in sync. | ||
*/ | ||
instanceId: string | ||
instanceId: z.string(), | ||
|
||
/** The width of the viewport (as percentage of viewport height) */ | ||
width: number | ||
|
||
width: z.number(), | ||
/** Current position of the viewport */ | ||
position: ViewPortPosition | ||
} | ||
/** Defines a position of the viewport */ | ||
export interface ViewPortPosition { | ||
/** | ||
* The Part which the current offset is calculated from. | ||
* `null` means "top of page" | ||
*/ | ||
scrollOffsetTarget: SegmentId | PartId | TextMarkerId | null | ||
/** The position of the ViewPort */ | ||
scrollOffset: number | ||
} | ||
/** TBD, something used to mark places in ScriptContents */ | ||
export type TextMarkerId = ProtectedString<'TextMarkerId', string> | ||
position: ViewPortPositionSchema, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,20 @@ | ||
import { z } from 'zod' | ||
import { AnyProtectedString } from '../ProtectedString.js' | ||
|
||
export interface DataObject { | ||
_id: AnyProtectedString | ||
} | ||
/** | ||
* Convenience function, defines a zod string but infers a ProtectedString | ||
* Usage: ZodProtectedString<MyProtectedStringType>() | ||
*/ | ||
export function ZodProtectedString<T extends AnyProtectedString>(): Omit< | ||
z.ZodString, | ||
'_type' | '_output' | '_input' | ||
> & { | ||
_type: T | ||
_output: T | ||
_input: T | ||
} { | ||
return z.string() as any | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters