Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ucanto/client

Package Overview
Dependencies
Maintainers
3
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ucanto/client - npm Package Compare versions

Comparing version 5.1.0 to 7.0.0

8

dist/src/connection.d.ts
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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc