UNPKG

@jsonjoy.com/reactive-rpc

Version:

Reactive-RPC is a library for building reactive APIs over WebSocket, HTTP, and other RPCs.

35 lines 1.56 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.new_ = void 0; const schema_1 = require("../schema"); const new_ = ({ t, services }) => (r) => { const Request = t.Object(t.prop('id', schema_1.BlockIdRef).options({ title: 'New block ID', description: 'The ID of the new block. Must be a unique ID, if the block already exists it will return an error.', }), t.propOpt('batch', schema_1.BlockBatchPartialRef).options({ title: 'Batch', description: 'A collection of patches to apply to the new block.', })); const Response = t.Object(t.prop('snapshot', schema_1.BlockSnapshotReturnRef)).options({ title: 'New block creation response', description: 'The response object for the new block creation, contains server generated metadata without blobs supplied by the client.', }); const Func = t.Function(Request, Response).options({ title: 'Create Block', intro: 'Creates a new block out of patches.', description: 'Creates a new block out of supplied patches. A block starts empty with an `undefined` state, and patches are applied to it.', }); return r.prop('block.new', Func, async ({ id, batch }) => { const { block } = await services.blocks.create(id, batch); const snapshot = block.snapshot; return { snapshot: { id, seq: snapshot.seq, ts: snapshot.ts, }, }; }); }; exports.new_ = new_; //# sourceMappingURL=new.js.map