Skip to content

Commit

Permalink
style(reactive-rpc): 💄 run Prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Dec 8, 2023
1 parent 759e00e commit 6092ccc
Show file tree
Hide file tree
Showing 15 changed files with 377 additions and 365 deletions.
8 changes: 3 additions & 5 deletions src/reactive-rpc/common/testing/buildE2eClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,12 @@ export const buildE2eClient = <Caller extends RpcCaller<any>>(caller: Caller, op
};
};

type UnTypeRouterCaller<T> = T extends TypeRouterCaller<infer R>
? R
: T extends ObjectValueCaller<infer R>
? R : never;
type UnTypeRouterCaller<T> = T extends TypeRouterCaller<infer R> ? R : T extends ObjectValueCaller<infer R> ? R : never;
type UnTypeRouter<T> = T extends TypeRouter<infer R>
? R
: T extends ObjectValue<infer R>
? ObjectValueToTypeMap<UnObjectType<R>> : never;
? ObjectValueToTypeMap<UnObjectType<R>>
: never;
type UnwrapFunction<F> = F extends FunctionType<infer Req, infer Res>
? (req: ResolveType<Req>) => Promise<ResolveType<Res>>
: F extends FunctionStreamingType<infer Req, infer Res>
Expand Down
20 changes: 11 additions & 9 deletions src/server/routes/blocks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@ import {Block, BlockId, BlockPatch, BlockSeq} from './schema';
import {history} from './methods/history';
import type {RouteDeps, Router, RouterBase} from '../types';

export const blocks = (d: RouteDeps) => <R extends RouterBase>(r: Router<R>) => {
const {system} = d;
export const blocks =
(d: RouteDeps) =>
<R extends RouterBase>(r: Router<R>) => {
const {system} = d;

system.alias('BlockId', BlockId);
system.alias('BlockSeq', BlockSeq);
system.alias('Block', Block);
system.alias('BlockPatch', BlockPatch);
system.alias('BlockId', BlockId);
system.alias('BlockSeq', BlockSeq);
system.alias('Block', Block);
system.alias('BlockPatch', BlockPatch);

// prettier-ignore
return (
// prettier-ignore
return (
( create(d)
( get(d)
( remove(d)
( edit(d)
( listen(d)
( history(d)
( r ))))))));
};
};
40 changes: 20 additions & 20 deletions src/server/routes/blocks/methods/create.ts
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 {};
});
};
72 changes: 36 additions & 36 deletions src/server/routes/blocks/methods/edit.ts
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,
};
});
};
50 changes: 25 additions & 25 deletions src/server/routes/blocks/methods/get.ts
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,
};
});
};
58 changes: 29 additions & 29 deletions src/server/routes/blocks/methods/history.ts
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};
});
};
58 changes: 29 additions & 29 deletions src/server/routes/blocks/methods/listen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,39 @@ import {switchMap} from 'rxjs';
import type {RouteDeps, Router, RouterBase} from '../../types';
import type {BlockId, BlockPatch, Block} from '../schema';

export const listen = ({t, services}: RouteDeps) => <R extends RouterBase>(r: Router<R>) => {
const PatchType = t.Ref<typeof BlockPatch>('BlockPatch');
export const listen =
({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: 'Block ID',
description: 'The ID of the block to subscribe to.',
}),
);
const Request = t.Object(
t.prop('id', t.Ref<typeof BlockId>('BlockId')).options({
title: 'Block ID',
description: 'The ID of the block to subscribe to.',
}),
);

const Response = t.Object(
t.propOpt('deleted', t.Boolean()).options({
title: 'Deleted',
description: 'Emitted only when the block is deleted.',
}),
t.propOpt('block', t.Ref<typeof Block>('Block')).options({
title: 'Block',
description: 'The whole block object, emitted only when the block is created.',
}),
t.propOpt('patches', t.Array(PatchType)).options({
title: 'Latest patches',
description: 'Patches that have been applied to the block.',
}),
);
const Response = t.Object(
t.propOpt('deleted', t.Boolean()).options({
title: 'Deleted',
description: 'Emitted only when the block is deleted.',
}),
t.propOpt('block', t.Ref<typeof Block>('Block')).options({
title: 'Block',
description: 'The whole block object, emitted only when the block is created.',
}),
t.propOpt('patches', t.Array(PatchType)).options({
title: 'Latest patches',
description: 'Patches that have been applied to the block.',
}),
);

const Func = t
.Function$(Request, Response)
.options({
const Func = t.Function$(Request, Response).options({
title: 'Listen for block changes',
description: 'Subscribe to a block to receive updates when it changes.',
});

return r.prop('blocks.listen', Func, (req$) => {
return req$.pipe(switchMap(({id}) => services.pubsub.listen$(`__block:${id}`))) as any;
});
};
return r.prop('blocks.listen', Func, (req$) => {
return req$.pipe(switchMap(({id}) => services.pubsub.listen$(`__block:${id}`))) as any;
});
};
Loading

0 comments on commit 6092ccc

Please sign in to comment.