@@ -0,0 +1,24 @@
|
||||
/** Writes the terminal protocol as JSON Schema, for generating the app's models. */
|
||||
import { mkdirSync, writeFileSync } from 'fs';
|
||||
import { join } from 'path';
|
||||
import { z } from 'zod';
|
||||
import {
|
||||
imageUploadResponseSchema, registerTerminalRequestSchema, registerTerminalResponseSchema, syncRequestSchema,
|
||||
syncResponseSchema, terminalEventSchema,
|
||||
} from '../src/terminal';
|
||||
|
||||
const schemas = {
|
||||
TerminalEvent: [terminalEventSchema, 'input'],
|
||||
RegisterTerminalRequest: [registerTerminalRequestSchema, 'input'],
|
||||
RegisterTerminalResponse: [registerTerminalResponseSchema, 'output'],
|
||||
SyncRequest: [syncRequestSchema, 'input'],
|
||||
SyncResponse: [syncResponseSchema, 'output'],
|
||||
ImageUploadResponse: [imageUploadResponseSchema, 'output'],
|
||||
} as const;
|
||||
|
||||
const out = join(__dirname, '..', 'schema');
|
||||
mkdirSync(out, { recursive: true });
|
||||
for (const [name, [schema, io]] of Object.entries(schemas)) {
|
||||
writeFileSync(join(out, `${name}.json`), JSON.stringify(z.toJSONSchema(schema, { io }), null, 2) + '\n');
|
||||
}
|
||||
console.log(`Wrote ${Object.keys(schemas).length} schemas to ${out}`);
|
||||
Reference in New Issue
Block a user