@ucanto/client
Advanced tools
Comparing version 5.1.0 to 7.0.0
export function connect<T extends Record<string, any>>(options: API.ConnectionOptions<T>): API.ConnectionView<T>; | ||
export function execute<C extends API.Capability<API.Ability, `${string}:${string}`, any>, T extends Record<string, any>, I extends API.Transport.Tuple<API.ServiceInvocation<C, T>>>(invocations: I, connection: API.Connection<T>): Promise<API.InferServiceInvocations<I, T>>; | ||
export function execute<C extends API.Capability<API.Ability, `${string}:${string}`, any>, T extends Record<string, any>, I extends API.Transport.Tuple<API.ServiceInvocation<C, T>>>(invocations: I, connection: API.Connection<T>): Promise<API.InferReceipts<I, T>>; | ||
import * as API from "@ucanto/interface"; | ||
@@ -15,4 +15,3 @@ /** | ||
options: API.ConnectionOptions<T>; | ||
encoder: API.RequestEncoder; | ||
decoder: API.ResponseDecoder; | ||
codec: API.OutboundCodec; | ||
channel: API.Channel<T>; | ||
@@ -24,6 +23,7 @@ hasher: API.MultihashHasher<number>; | ||
* @param {I} invocations | ||
* @returns {Promise<API.InferReceipts<I, T>>} | ||
*/ | ||
execute<C extends API.Capability<API.Ability, `${string}:${string}`, any>, I extends API.Transport.Tuple<API.ServiceInvocation<C, T>>>(...invocations: I): Promise<API.InferServiceInvocations<I, T>>; | ||
execute<C extends API.Capability<API.Ability, `${string}:${string}`, any>, I extends API.Transport.Tuple<API.ServiceInvocation<C, T>>>(...invocations: I): Promise<API.InferReceipts<I, T>>; | ||
} | ||
export {}; | ||
//# sourceMappingURL=connection.d.ts.map |
{ | ||
"name": "@ucanto/client", | ||
"description": "UCAN RPC Client", | ||
"version": "5.1.0", | ||
"version": "7.0.0", | ||
"keywords": [ | ||
@@ -24,4 +24,4 @@ "UCAN", | ||
"dependencies": { | ||
"multiformats": "^11.0.0", | ||
"@ucanto/interface": "^6.0.0" | ||
"@ucanto/interface": "^7.0.0", | ||
"@ucanto/core": "^7.0.0" | ||
}, | ||
@@ -39,5 +39,4 @@ "devDependencies": { | ||
"typescript": "^4.9.5", | ||
"@ucanto/core": "^5.1.0", | ||
"@ucanto/principal": "^5.1.0", | ||
"@ucanto/transport": "^5.1.0" | ||
"@ucanto/principal": "^7.0.0", | ||
"@ucanto/transport": "^7.0.0" | ||
}, | ||
@@ -73,3 +72,3 @@ "type": "module", | ||
"test:node": "c8 --check-coverage --branches 100 --functions 100 --lines 100 mocha test/**/*.spec.js", | ||
"test": "npm run test:node", | ||
"test": "c8 --check-coverage --branches 100 --functions 100 --lines 100 mocha --bail test/**/*.spec.js", | ||
"coverage": "c8 --reporter=html mocha test/test-*.js && npm_config_yes=true npx st -d coverage -p 8080", | ||
@@ -76,0 +75,0 @@ "check": "tsc --build", |
import * as API from '@ucanto/interface' | ||
import { sha256 } from 'multiformats/hashes/sha2' | ||
import { Signature, Message, Receipt, sha256 } from '@ucanto/core' | ||
@@ -11,3 +11,3 @@ /** | ||
*/ | ||
export const connect = (options) => new Connection(options) | ||
export const connect = options => new Connection(options) | ||
@@ -25,4 +25,3 @@ /** | ||
this.options = options | ||
this.encoder = options.encoder | ||
this.decoder = options.decoder | ||
this.codec = options.codec | ||
this.channel = options.channel | ||
@@ -35,4 +34,5 @@ this.hasher = options.hasher || sha256 | ||
* @param {I} invocations | ||
* @returns {Promise<API.InferReceipts<I, T>>} | ||
*/ | ||
execute(...invocations) { | ||
async execute(...invocations) { | ||
return execute(invocations, this) | ||
@@ -48,9 +48,45 @@ } | ||
* @param {I} invocations | ||
* @returns {Promise<API.InferServiceInvocations<I, T>>} | ||
* @returns {Promise<API.InferReceipts<I, T>>} | ||
*/ | ||
export const execute = async (invocations, connection) => { | ||
const request = await connection.encoder.encode(invocations, connection) | ||
const input = await Message.build({ invocations }) | ||
const request = await connection.codec.encode(input, connection) | ||
const response = await connection.channel.request(request) | ||
const result = await connection.decoder.decode(response) | ||
return result | ||
// We may fail to decode the response if content type is not supported | ||
// or if data was corrupted. We do not want to throw in such case however, | ||
// because client will get an Error object as opposed to a receipt, to retain | ||
// consistent client API with two kinds of errors we encode caught error as | ||
// a receipts per workflow invocation. | ||
try { | ||
const output = await connection.codec.decode(response) | ||
const receipts = input.invocationLinks.map(link => output.get(link)) | ||
return /** @type {API.InferReceipts<I, T>} */ (receipts) | ||
} catch (error) { | ||
// No third party code is run during decode and we know | ||
// we only throw an Error | ||
const { message, ...cause } = /** @type {Error} */ (error) | ||
const receipts = [] | ||
for await (const ran of input.invocationLinks) { | ||
const receipt = await Receipt.issue({ | ||
ran, | ||
result: { error: { ...cause, message } }, | ||
// @ts-expect-error - we can not really sign a receipt without having | ||
// an access to a signer which client does not have. In the future | ||
// we will change client API requiring a signer to be passed in but | ||
// for now we just use a dummy signer. | ||
issuer: { | ||
did() { | ||
return connection.id.did() | ||
}, | ||
sign() { | ||
return Signature.createNonStandard('', new Uint8Array()) | ||
}, | ||
}, | ||
}) | ||
receipts.push(receipt) | ||
} | ||
return /** @type {API.InferReceipts<I, T>} */ (receipts) | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6936
12
120
+ Added@ucanto/core@^7.0.0
+ Added@ipld/car@5.3.3(transitive)
+ Added@ucanto/core@7.1.1(transitive)
+ Added@ucanto/interface@7.1.0(transitive)
+ Addedvarint@6.0.0(transitive)
- Removedmultiformats@^11.0.0
- Removed@ucanto/interface@6.2.0(transitive)
Updated@ucanto/interface@^7.0.0