feat: some shit
Some checks failed
Deploy to GitHub Pages / build_site (push) Has been cancelled

This commit is contained in:
2024-12-20 12:21:46 +01:00
parent 9d698be86f
commit eadd37bfa4
5 changed files with 4 additions and 4 deletions

View File

@@ -0,0 +1,81 @@
import { z } from "@hono/zod-openapi";
const DefaultOptionsSchema = z.object({
internal: z.boolean().optional(),
external: z.boolean().optional(),
setting: z.string().optional(),
label: z.string().optional(),
description: z.string().optional(),
accepts: z.array(z.string()).optional(),
hidden: z.boolean().optional(),
});
const NodeInputFloatSchema = z.object({
...DefaultOptionsSchema.shape,
type: z.literal("float"),
element: z.literal("slider").optional(),
value: z.number().optional(),
min: z.number().optional(),
max: z.number().optional(),
step: z.number().optional(),
});
const NodeInputIntegerSchema = z.object({
...DefaultOptionsSchema.shape,
type: z.literal("integer"),
element: z.literal("slider").optional(),
value: z.number().optional(),
min: z.number().optional(),
max: z.number().optional(),
});
const NodeInputBooleanSchema = z.object({
...DefaultOptionsSchema.shape,
type: z.literal("boolean"),
value: z.boolean().optional(),
});
const NodeInputSelectSchema = z.object({
...DefaultOptionsSchema.shape,
type: z.literal("select"),
options: z.array(z.string()).optional(),
value: z.number().optional(),
});
const NodeInputSeedSchema = z.object({
...DefaultOptionsSchema.shape,
type: z.literal("seed"),
value: z.number().optional(),
});
const NodeInputVec3Schema = z.object({
...DefaultOptionsSchema.shape,
type: z.literal("vec3"),
value: z.array(z.number()).optional(),
});
const NodeInputGeometrySchema = z.object({
...DefaultOptionsSchema.shape,
type: z.literal("geometry"),
});
const NodeInputPathSchema = z.object({
...DefaultOptionsSchema.shape,
type: z.literal("path"),
});
export const NodeInputSchema = z
.union([
NodeInputSeedSchema,
NodeInputBooleanSchema,
NodeInputFloatSchema,
NodeInputIntegerSchema,
NodeInputSelectSchema,
NodeInputSeedSchema,
NodeInputVec3Schema,
NodeInputGeometrySchema,
NodeInputPathSchema,
])
.openapi("NodeInput");
export type NodeInput = z.infer<typeof NodeInputSchema>;

View File

@@ -0,0 +1,31 @@
import { z } from "zod";
import { NodeInputSchema } from "./inputs.ts";
export type NodeId = `${string}/${string}/${string}`;
export const idRegex = /[a-z0-9-]+/i;
const idSchema = z
.string()
.regex(
new RegExp(
`^(${idRegex.source})/(${idRegex.source})/(${idRegex.source})$`,
),
"Invalid id format",
);
export const NodeDefinitionSchema = z
.object({
id: idSchema,
inputs: z.record(NodeInputSchema).optional(),
outputs: z.array(z.string()).optional(),
meta: z
.object({
description: z.string().optional(),
title: z.string().optional(),
})
.optional(),
})
.openapi("NodeDefinition");
export type NodeDefinition = z.infer<typeof NodeDefinitionSchema>;