json-crdt-server
Version:
JSON CRDT server and syncing local-first browser client
44 lines (43 loc) • 1.94 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.scan = void 0;
const schema_1 = require("../schema");
const scan = ({ t, services }) => (r) => {
const Request = t.Object(t.prop('id', schema_1.BlockIdRef).options({
title: 'Block ID',
description: 'The ID of the block.',
}), t.propOpt('seq', schema_1.BlockCurRef).options({
title: 'Starting Sequence Number',
description: 'The sequence number to start from. Defaults to the latest sequence number.',
}), t
.propOpt('limit', t.num.options({
format: 'u16',
gte: 0,
lte: 1000,
}))
.options({
title: 'Number of Patches',
description: 'The minimum number of patches to return. Defaults to 10. ' +
'When positive, returns the patches ahead of the starting sequence number. ' +
'When negative, returns the patches behind the starting sequence number.',
}), t.propOpt('snapshot', t.bool).options({
title: 'Include Start Snapshot',
description: 'If true, includes the snapshot of state at the start of the sequence.',
}));
const Response = t.Object(t.prop('batches', t.Array(schema_1.BlockBatchRef)).options({
title: 'Batches',
description: 'List of batches in given sequence range.',
}), t.propOpt('snapshot', schema_1.BlockSnapshotRef).options({
title: 'Start Snapshot',
description: 'The state of the block right before the first batch in the result.',
}));
const Func = t.Function(Request, Response).options({
title: 'Block History',
intro: 'Fetch block history.',
description: 'Returns a list of specified change patches for a block.',
});
return r.prop('block.scan', Func, async ({ id, seq, limit = 10, snapshot }) => {
return await services.blocks.scan(id, !!snapshot, seq, limit);
});
};
exports.scan = scan;
;