Skip to content

Commit

Permalink
feature: add zod schemas (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
idleberg committed Oct 16, 2023
1 parent 39ceb9b commit 7adad4b
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 1 deletion.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@
"test": "uvu tests -r tsm"
},
"dependencies": {
"log-symbols": "^5.1.0"
"log-symbols": "^5.1.0",
"zod": "^3.22.4"
},
"devDependencies": {
"@types/node": "^18.11.18",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions src/schema/effect-list.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { z } from 'zod';

const RANGE_0_255 = z.number().int().min(0).max(255);
const BLEND_MODES = z.union([
z.literal('IGNORE'),
z.literal('REPLACE'),
z.literal('5050'),
z.literal('MAXIMUM'),
z.literal('ADDITIVE'),
z.literal('SUB_1'), // TODO verify
z.literal('SUB_2'), // TODO verify
z.literal('EVERY_OTHER_LINE'),
z.literal('EVERY_OTHER_PIXEL'),
z.literal('XOR'),
z.literal('ADJUSTABLE'),
z.literal('MULTIPLY'),
z.literal('BUFFER'),
z.literal('MINIMUM')
]);

export const effectList = z.object({
type: z.literal('EffectList'),
enabled: z.boolean(),
clearFrame: z.boolean(),
input: BLEND_MODES,
output: BLEND_MODES,
inAdjustBlend: RANGE_0_255,
outAdjustBlend: RANGE_0_255,
inBuffer: z.number().int().min(1).max(8),
outBuffer: z.number().int().min(1).max(8),
inBufferInvert: z.boolean(),
outBufferInvert: z.boolean(),
enableOnBeat: z.boolean(),
enableOnBeatFor: z.number().int().min(0).safe(), // TODO validate
code: z.object({
enabled: z.boolean(),
init: z.string(),
perFrame: z.string()
}),
// TODO components: []
}).required();

export type EffectList = z.infer<typeof effectList>;
77 changes: 77 additions & 0 deletions src/schema/trans.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import { z } from 'zod';

const MISC = z.literal('Misc');
const RANGE_0_255 = z.number().int().min(0).max(255);

export const bufferSave = z.object({
type: z.literal('BufferSave'),
group: MISC,
action: z.union([
z.literal('SAVE'),
z.literal('RESTORE'),
z.literal('ALTERNATE_SAVE_RESTORE'),
z.literal('ALTERNATE_RESTORE_SAVE')
]),
bufferId: z.number().int().min(1).max(8),
blendMode: z.union([
z.literal('IGNORE'),
z.literal('REPLACE'),
z.literal('FIFTY_FIFTY'),
z.literal('MAXIMUM'),
z.literal('ADDITIVE'),
z.literal('SUB_DEST_SRC'),
z.literal('SUB_SRC_DEST'),
z.literal('EVERY_OTHER_LINE'),
z.literal('EVERY_OTHER_PIXEL'),
z.literal('XOR'),
z.literal('ADJUSTABLE'),
z.literal('MULTIPLY'),
z.literal('BUFFER')
]),
adjustBlend: RANGE_0_255
}).required();

export const comment = z.object({
type: z.literal('Comment'),
group: MISC,
text: z.string()
}).required();

export const customBpm = z.object({
type: z.literal('CustomBPM'),
group: MISC,
enabled: z.boolean(),
mode: z.union([
z.literal('ARBITRARY'),
z.literal('SKIP'),
z.literal('REVERSE')
]),
arbitraryValue: RANGE_0_255,
skipValue: RANGE_0_255,
skipFirstBeats: RANGE_0_255
}).required();

export const setRenderMode = z.object({
type: z.literal('SetRenderMode'),
group: MISC,
blend: z.union([
z.literal('BLEND_REPLACE'),
z.literal('BLEND_ADDITIVE'),
z.literal('BLEND_MAXIMUM'),
z.literal('BLEND_5050'),
z.literal('BLEND_SUB1'),
z.literal('BLEND_SUB2'),
z.literal('BLEND_MULTIPLY'),
z.literal('BLEND_ADJUSTABLE'),
z.literal('BLEND_XOR'),
z.literal('BLEND_MINIMUM'),
]),
adjustBlend: RANGE_0_255,
lineSize: RANGE_0_255,
enabled: z.boolean()
}).required();

export type BufferSave = z.infer<typeof bufferSave>;
export type Comment = z.infer<typeof comment>;
export type CustomBpm = z.infer<typeof customBpm>;
export type SetRenderMode = z.infer<typeof setRenderMode>;

0 comments on commit 7adad4b

Please sign in to comment.