-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(rpc/server): adds server types and defaults
- Loading branch information
Showing
4 changed files
with
49 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './server'; | ||
export * from './validate'; | ||
export * from './types'; |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { RPCServerOptions } from './types'; | ||
import { DataOutput, DataInput } from '~/types'; | ||
|
||
export function createDefaults(): Required<Omit<RPCServerOptions, 'default'>> { | ||
return { | ||
children: true, | ||
parser: { | ||
serialize(data: object): DataOutput { | ||
return JSON.stringify(data); | ||
}, | ||
deserialize(data: DataInput): object { | ||
return JSON.parse(String(data)); | ||
} | ||
} | ||
}; | ||
} |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './types'; |
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { QueryServiceImplementation } from '@karmic/core'; | ||
import { DataOutput, DataInput, DataParser } from '~/types'; | ||
|
||
export interface RPCServerOptions { | ||
/** | ||
* Whether to create routes for type's children services. | ||
* Default: `true`. | ||
*/ | ||
children?: boolean; | ||
/** | ||
* Serializer and deserializer | ||
*/ | ||
parser?: DataParser; | ||
/** | ||
* A default service for adapters to use when the route is non existent. | ||
* Defaults to a `ClientNotFound` error throwing service. | ||
*/ | ||
default?: QueryServiceImplementation; | ||
} | ||
|
||
export interface RPCServerConnect { | ||
send: (data: DataOutput) => void | Promise<void>; | ||
fatal: (error: Error) => void; | ||
} | ||
|
||
export type RPCServerProvideContext<T = any> = () => Promise<T> | T; | ||
|
||
export interface RPCServerConnection { | ||
request: (data: DataInput) => void; | ||
close: () => void; | ||
} |