-
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
377 additions
and
365 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
import type {RouteDeps, Router, RouterBase} from '../../types'; | ||
import type {BlockId, BlockPatch} from '../schema'; | ||
|
||
export const create = ({t, services}: RouteDeps) => <R extends RouterBase>(r: Router<R>) => { | ||
const Request = t.Object( | ||
t.prop('id', t.Ref<typeof BlockId>('BlockId')).options({ | ||
title: 'New block ID', | ||
description: 'The ID of the new block.', | ||
}), | ||
t.prop('patches', t.Array(t.Ref<typeof BlockPatch>('BlockPatch'))).options({ | ||
title: 'Patches', | ||
description: 'The patches to apply to the document.', | ||
}), | ||
); | ||
export const create = | ||
({t, services}: RouteDeps) => | ||
<R extends RouterBase>(r: Router<R>) => { | ||
const Request = t.Object( | ||
t.prop('id', t.Ref<typeof BlockId>('BlockId')).options({ | ||
title: 'New block ID', | ||
description: 'The ID of the new block.', | ||
}), | ||
t.prop('patches', t.Array(t.Ref<typeof BlockPatch>('BlockPatch'))).options({ | ||
title: 'Patches', | ||
description: 'The patches to apply to the document.', | ||
}), | ||
); | ||
|
||
const Response = t.obj; | ||
const Response = t.obj; | ||
|
||
const Func = t | ||
.Function(Request, Response) | ||
.options({ | ||
const Func = t.Function(Request, Response).options({ | ||
title: 'Create Block', | ||
intro: 'Creates a new block or applies patches to it.', | ||
description: 'Creates a new block or applies patches to it.', | ||
}); | ||
|
||
return r.prop('blocks.create', Func, async ({id, patches}) => { | ||
const {block} = await services.blocks.create(id, patches); | ||
return {}; | ||
}); | ||
}; | ||
return r.prop('blocks.create', Func, async ({id, patches}) => { | ||
const {block} = await services.blocks.create(id, patches); | ||
return {}; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,47 @@ | ||
import type {RouteDeps, Router, RouterBase} from '../../types'; | ||
import type {BlockId, BlockPatch} from '../schema'; | ||
|
||
export const edit = ({t, services}: RouteDeps) => <R extends RouterBase>(r: Router<R>) => { | ||
const PatchType = t.Ref<typeof BlockPatch>('BlockPatch'); | ||
export const edit = | ||
({t, services}: RouteDeps) => | ||
<R extends RouterBase>(r: Router<R>) => { | ||
const PatchType = t.Ref<typeof BlockPatch>('BlockPatch'); | ||
|
||
const Request = t.Object( | ||
t.prop('id', t.Ref<typeof BlockId>('BlockId')).options({ | ||
title: 'Document ID', | ||
description: 'The ID of the document to apply the patch to.', | ||
}), | ||
// This can be inferred from the "seq" of the first patch: | ||
// t.prop('seq', t.Ref<typeof BlockSeq>('BlockSeq')).options({ | ||
// title: 'Last known sequence number', | ||
// description: | ||
// 'The last known sequence number of the document. ' + | ||
// 'If the document has changed since this sequence number, ' + | ||
// 'the response will contain all the necessary patches for the client to catch up.', | ||
// }), | ||
t.prop('patches', t.Array(PatchType)).options({ | ||
title: 'Patches', | ||
description: 'The patches to apply to the document.', | ||
}), | ||
); | ||
const Request = t.Object( | ||
t.prop('id', t.Ref<typeof BlockId>('BlockId')).options({ | ||
title: 'Document ID', | ||
description: 'The ID of the document to apply the patch to.', | ||
}), | ||
// This can be inferred from the "seq" of the first patch: | ||
// t.prop('seq', t.Ref<typeof BlockSeq>('BlockSeq')).options({ | ||
// title: 'Last known sequence number', | ||
// description: | ||
// 'The last known sequence number of the document. ' + | ||
// 'If the document has changed since this sequence number, ' + | ||
// 'the response will contain all the necessary patches for the client to catch up.', | ||
// }), | ||
t.prop('patches', t.Array(PatchType)).options({ | ||
title: 'Patches', | ||
description: 'The patches to apply to the document.', | ||
}), | ||
); | ||
|
||
const Response = t.Object( | ||
t.prop('patches', t.Array(PatchType)).options({ | ||
title: 'Latest patches', | ||
description: 'The list of patches that the client might have missed and should apply to the document.', | ||
}), | ||
); | ||
const Response = t.Object( | ||
t.prop('patches', t.Array(PatchType)).options({ | ||
title: 'Latest patches', | ||
description: 'The list of patches that the client might have missed and should apply to the document.', | ||
}), | ||
); | ||
|
||
const Func = t | ||
.Function(Request, Response) | ||
.options({ | ||
const Func = t.Function(Request, Response).options({ | ||
title: 'Edit Block', | ||
intro: 'Applies patches to an existing block.', | ||
description: 'Applies patches to an existing document and returns the latest concurrent changes.', | ||
}); | ||
|
||
return r.prop('blocks.edit', Func, async ({id, patches}) => { | ||
const res = await services.blocks.edit(id, patches); | ||
return { | ||
patches: res.patches, | ||
}; | ||
}); | ||
}; | ||
return r.prop('blocks.edit', Func, async ({id, patches}) => { | ||
const res = await services.blocks.edit(id, patches); | ||
return { | ||
patches: res.patches, | ||
}; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,35 @@ | ||
import type {RouteDeps, Router, RouterBase} from '../../types'; | ||
import type {Block, BlockId, BlockPatch} from '../schema'; | ||
|
||
export const get = ({t, services}: RouteDeps) => <R extends RouterBase>(r: Router<R>) => { | ||
const Request = t.Object( | ||
t.prop('id', t.Ref<typeof BlockId>('BlockId')).options({ | ||
title: 'Block ID', | ||
description: 'The ID of the block to retrieve.', | ||
}), | ||
); | ||
export const get = | ||
({t, services}: RouteDeps) => | ||
<R extends RouterBase>(r: Router<R>) => { | ||
const Request = t.Object( | ||
t.prop('id', t.Ref<typeof BlockId>('BlockId')).options({ | ||
title: 'Block ID', | ||
description: 'The ID of the block to retrieve.', | ||
}), | ||
); | ||
|
||
const Response = t.Object( | ||
t.prop('block', t.Ref<typeof Block>('Block').options({})), | ||
t.prop('patches', t.Array(t.Ref<typeof BlockPatch>('BlockPatch'))).options({ | ||
title: 'Patches', | ||
description: 'The list of all patches.', | ||
}), | ||
); | ||
const Response = t.Object( | ||
t.prop('block', t.Ref<typeof Block>('Block').options({})), | ||
t.prop('patches', t.Array(t.Ref<typeof BlockPatch>('BlockPatch'))).options({ | ||
title: 'Patches', | ||
description: 'The list of all patches.', | ||
}), | ||
); | ||
|
||
const Func = t | ||
.Function(Request, Response) | ||
.options({ | ||
const Func = t.Function(Request, Response).options({ | ||
title: 'Read Block', | ||
intro: 'Retrieves a block by ID.', | ||
description: 'Fetches a block by ID.', | ||
}); | ||
|
||
return r.prop('blocks.get', Func, async ({id}) => { | ||
const {block, patches} = await services.blocks.get(id); | ||
return { | ||
block, | ||
patches, | ||
}; | ||
}); | ||
}; | ||
return r.prop('blocks.get', Func, async ({id}) => { | ||
const {block, patches} = await services.blocks.get(id); | ||
return { | ||
block, | ||
patches, | ||
}; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,39 @@ | ||
import type {BlockPatch, BlockId} from '../schema'; | ||
import type {RouteDeps, Router, RouterBase} from '../../types'; | ||
|
||
export const history = ({t, services}: RouteDeps) => <R extends RouterBase>(r: Router<R>) => { | ||
const Request = t.Object( | ||
t.prop('id', t.Ref<typeof BlockId>('BlockId')).options({ | ||
title: 'Block ID', | ||
description: 'The ID of the block.', | ||
}), | ||
t.prop('max', t.num.options({format: 'u32'})).options({ | ||
title: 'Max', | ||
description: 'The maximum sequence number to return.', | ||
}), | ||
t.prop('min', t.num.options({format: 'u32'})).options({ | ||
title: 'Min', | ||
description: 'The minimum sequence number to return.', | ||
}), | ||
); | ||
export const history = | ||
({t, services}: RouteDeps) => | ||
<R extends RouterBase>(r: Router<R>) => { | ||
const Request = t.Object( | ||
t.prop('id', t.Ref<typeof BlockId>('BlockId')).options({ | ||
title: 'Block ID', | ||
description: 'The ID of the block.', | ||
}), | ||
t.prop('max', t.num.options({format: 'u32'})).options({ | ||
title: 'Max', | ||
description: 'The maximum sequence number to return.', | ||
}), | ||
t.prop('min', t.num.options({format: 'u32'})).options({ | ||
title: 'Min', | ||
description: 'The minimum sequence number to return.', | ||
}), | ||
); | ||
|
||
const Response = t.Object( | ||
t.prop('patches', t.Array(t.Ref<typeof BlockPatch>('BlockPatch'))).options({ | ||
title: 'Patches', | ||
description: 'The list of patches.', | ||
}), | ||
); | ||
const Response = t.Object( | ||
t.prop('patches', t.Array(t.Ref<typeof BlockPatch>('BlockPatch'))).options({ | ||
title: 'Patches', | ||
description: 'The list of patches.', | ||
}), | ||
); | ||
|
||
const Func = t | ||
.Function(Request, Response) | ||
.options({ | ||
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('blocks.history', Func, async ({id, min, max}) => { | ||
const {patches} = await services.blocks.history(id, min, max); | ||
return {patches}; | ||
}); | ||
}; | ||
return r.prop('blocks.history', Func, async ({id, min, max}) => { | ||
const {patches} = await services.blocks.history(id, min, max); | ||
return {patches}; | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.