import {
and,
api,
object,
operation,
string,
subscription,
} from '@livon/schema';
const MessageInput = object({
name: 'MessageInput',
shape: {
author: string(),
text: string(),
},
});
const WithId = object({ name: 'WithId', shape: { id: string() } });
const MessageWithId = and({ left: MessageInput, right: WithId });
const sendMessage = operation({
input: MessageInput,
output: MessageWithId,
exec: async (input) => ({ ...input, id: 'msg-1' }),
publish: {
onMessage: (output) => output,
},
});
export const ApiSchema = api({
operations: {sendMessage},
subscriptions: {onMessage: subscription({payload: MessageWithId})},
});
export const serverSchema = ApiSchema;