-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
simplify upload-api-proxy and remove redundancies by e.g. inferring s…
…tore/upload service types from the capability defs
- Loading branch information
Showing
5 changed files
with
75 additions
and
95 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
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,10 +1,53 @@ | ||
import { | ||
Capability, | ||
InferInvokedCapability, | ||
Invocation, | ||
InvocationContext, | ||
Match, | ||
ParsedCapability, | ||
RequestDecoder, | ||
RequestEncoder, | ||
ResponseDecoder, | ||
ResponseEncoder, | ||
Result, | ||
TheCapabilityParser, | ||
} from '@ucanto/interface' | ||
|
||
export interface ClientCodec extends RequestEncoder, ResponseDecoder {} | ||
|
||
export interface ServerCodec extends RequestDecoder, ResponseEncoder {} | ||
|
||
/** | ||
* A single ucanto service method. | ||
*/ | ||
export type InvocationResponder< | ||
C extends Capability, | ||
Success = unknown, | ||
Failure extends { error: true } = { error: true } | ||
> = ( | ||
invocation: Invocation<C>, | ||
context: InvocationContext | ||
) => Promise<Result<Success, Failure>> | ||
|
||
/** | ||
* Select from T the property names whose values are of type V | ||
*/ | ||
export type KeysWithValue<T, V> = { | ||
[K in keyof T]-?: T[K] extends V ? K : never | ||
}[keyof T] | ||
|
||
/** | ||
* Infer ucanto service object from a namespace object containing CapabilityParsers | ||
* | ||
* @example InferService<import('@web3-storage/capabilities/upload')> | ||
*/ | ||
export type InferService< | ||
S extends Record<string, unknown>, | ||
CP extends TheCapabilityParser<Match<ParsedCapability>> = TheCapabilityParser< | ||
Match<ParsedCapability> | ||
> | ||
> = { | ||
[K in KeysWithValue<S, CP>]: InvocationResponder< | ||
InferInvokedCapability<S[K] extends CP ? S[K] : never> | ||
> | ||
} |
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