Skip to content

Commit

Permalink
feat!: upgrades to multiformats@10 (#117)
Browse files Browse the repository at this point in the history
* chore: update interface to multiformats@10

* feat: upgrade to multiformat@10

* chore: undo irrelevant chages
  • Loading branch information
Gozala authored Oct 20, 2022
1 parent 12efb30 commit 61dc4ca
Show file tree
Hide file tree
Showing 27 changed files with 2,139 additions and 1,004 deletions.
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
"format:check": "prettier --check '**/*.{js,ts,yml,json}' --ignore-path .gitignore",
"test": "pnpm -r run --if-present test",
"build": "pnpm -r run --if-present build",
"typecheck": "pnpm -r run --if-present typecheck",
"check": "pnpm -r run --if-present check",
"test:node": "pnpm -r run --if-present test:node",
"test:web": "pnpm -r run --if-present test:web"
},
"devDependencies": {
"mocha": "^10.0.0",
"mocha": "^10.1.0",
"prettier": "2.7.1",
"typescript": "4.8.3"
},
Expand All @@ -31,5 +31,10 @@
"semi": false,
"singleQuote": true,
"arrowParens": "avoid"
},
"pnpm": {
"overrides": {
"multiformats": "^10.0.0"
}
}
}
10 changes: 4 additions & 6 deletions packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,15 @@
"test:node": "c8 --check-coverage --branches 100 --functions 100 --lines 100 mocha test/**/*.spec.js",
"test": "npm run test:node",
"coverage": "c8 --reporter=html mocha test/test-*.js && npm_config_yes=true npx st -d coverage -p 8080",
"typecheck": "tsc --build",
"check": "tsc --build",
"build": "tsc --build"
},
"dependencies": {
"@ucanto/interface": "^2.0.0",
"multiformats": "^9.8.1"
"multiformats": "^10.0.0"
},
"devDependencies": {
"@types/chai": "^4.3.3",
"@types/chai-subset": "^1.3.3",
"@types/mocha": "^9.1.0",
"@ucanto/principal": "^2.0.0",
"@ucanto/core": "^2.0.0",
Expand All @@ -43,11 +42,10 @@
"@web-std/file": "^3.0.2",
"c8": "^7.11.0",
"chai": "^4.3.6",
"chai-subset": "^1.6.0",
"mocha": "^10.0.0",
"mocha": "^10.1.0",
"nyc": "^15.1.0",
"playwright-test": "^8.1.1",
"typescript": "^4.8.3"
"typescript": "^4.8.4"
},
"type": "module",
"main": "src/lib.js",
Expand Down
4 changes: 1 addition & 3 deletions packages/client/test/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { assert, use } from 'chai'
import subset from 'chai-subset'
use(subset)
import { assert } from 'chai'

export const test = it
export { assert }
14 changes: 6 additions & 8 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,26 @@
"test:node": "c8 --check-coverage --branches 100 --functions 100 --lines 100 mocha test/*.spec.js",
"test": "npm run test:node",
"coverage": "c8 --reporter=html mocha test/*.spec.js && npm_config_yes=true npx st -d coverage -p 8080",
"typecheck": "tsc --build",
"check": "tsc --build",
"build": "tsc --build"
},
"dependencies": {
"@ipld/car": "^4.1.5",
"@ipld/car": "^4.1.6",
"@ipld/dag-cbor": "^7.0.3",
"@ipld/dag-ucan": "^4.0.0-beta",
"@ipld/dag-ucan": "^2.0.0",
"@ucanto/interface": "^2.0.0",
"multiformats": "^9.8.1"
"multiformats": "^10.0.0"
},
"devDependencies": {
"@types/chai": "^4.3.3",
"@types/chai-subset": "^1.3.3",
"@types/mocha": "^9.1.0",
"@ucanto/principal": "^2.0.0",
"c8": "^7.11.0",
"chai": "^4.3.6",
"chai-subset": "^1.6.0",
"mocha": "^10.0.0",
"mocha": "^10.1.0",
"nyc": "^15.1.0",
"playwright-test": "^8.1.1",
"typescript": "^4.8.3"
"typescript": "^4.8.4"
},
"type": "module",
"main": "src/lib.js",
Expand Down
3 changes: 1 addition & 2 deletions packages/core/src/lib.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ export { delegate, isDelegation } from './delegation.js'
export { invoke } from './invocation.js'
export {
create as createLink,
createV0 as createLegacyLink,
createLegacy as createLegacyLink,
isLink,
asLink,
parse as parseLink,
decode as decodeLink,
} from './link.js'
Expand Down
42 changes: 1 addition & 41 deletions packages/core/src/link.js
Original file line number Diff line number Diff line change
@@ -1,41 +1 @@
import { CID } from 'multiformats'
import * as API from '@ucanto/interface'

/**
* @template {number} Code
* @template {number} Alg
* @param {Code} code
* @param {API.MultihashDigest<Alg>} digest
* @return {API.Link<unknown, Code, Alg>}
*/
export const create = (code, digest) =>
/** @type {any} */ (CID.createV1(code, digest))

/**
* @template {number} Alg
* @param {API.MultihashDigest<Alg>} digest
* @return {API.Link<unknown, 0x70, Alg, 0>}
*/
export const createV0 = digest => /** @type {any} */ (CID.createV0(digest))

/**
* Type predicate returns true if value is the link.
*
* @template {API.Link} L
* @param {unknown} value
* @returns {value is L}
*/
export const isLink = value =>
value != null && /** @type {{asCID: unknown}} */ (value).asCID === value

export const asLink =
/** @type {<L extends API.Link<unknown, number, number, API.UCAN.CIDVersion>>(value:L|unknown) => L|null} */
(CID.asCID)

export const parse =
/** @type {<P extends string>(source:string, base?:API.MultibaseDecoder<P>) => API.Link<unknown, number, number, API.UCAN.CIDVersion>} */
(CID.parse)

export const decode =
/** @type {(bytes:Uint8Array) => API.Link<unknown, number, number, API.UCAN.CIDVersion>} */
(CID.decode)
export * from 'multiformats/link'
10 changes: 5 additions & 5 deletions packages/core/test/invocation.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ test('encode invocation', async () => {

const delegation = await add.delegate()

assert.containSubset(delegation, {
assert.deepNestedInclude(delegation, {
capabilities: [
{
can: 'store/add',
Expand Down Expand Up @@ -44,7 +44,7 @@ test('expired invocation', async () => {
expiration,
})

assert.containSubset(await invocation.delegate(), {
assert.deepNestedInclude(await invocation.delegate(), {
capabilities: [
{
can: 'store/add',
Expand All @@ -67,7 +67,7 @@ test('invocation with notBefore', async () => {
notBefore,
})

assert.containSubset(await invocation.delegate(), {
assert.deepNestedInclude(await invocation.delegate(), {
capabilities: [
{
can: 'store/add',
Expand All @@ -89,7 +89,7 @@ test('invocation with nonce', async () => {
nonce: 'hello',
})

assert.containSubset(await invocation.delegate(), {
assert.deepNestedInclude(await invocation.delegate(), {
capabilities: [
{
can: 'store/add',
Expand All @@ -115,7 +115,7 @@ test('invocation with facts', async () => {
],
})

assert.containSubset(await invocation.delegate(), {
assert.deepNestedInclude(await invocation.delegate(), {
capabilities: [
{
can: 'store/add',
Expand Down
43 changes: 19 additions & 24 deletions packages/core/test/lib.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test('create delegation', async () => {
},
})

assert.containSubset(delegation, {
assert.deepNestedInclude(delegation, {
data,
cid,
bytes,
Expand All @@ -31,15 +31,12 @@ test('create delegation', async () => {
version: data.version,
signature: data.signature,

capabilities: {
...[
{
can: 'store/add',
with: alice.did(),
},
],
},

capabilities: [
{
can: 'store/add',
with: alice.did(),
},
],
notBefore: undefined,
expiration: data.expiration,
nonce: undefined,
Expand All @@ -51,7 +48,7 @@ test('create delegation', async () => {
assert.equal(delegation.audience.did(), bob.did())

const dag = [...delegation.export()]
assert.containSubset(dag, [
assert.deepEqual(dag, [
{
cid,
bytes,
Expand Down Expand Up @@ -79,7 +76,7 @@ test('create delegation (with just cid and bytes)', async () => {
},
})

assert.containSubset(delegation, {
assert.deepNestedInclude(delegation, {
data,
cid,
bytes,
Expand All @@ -88,14 +85,12 @@ test('create delegation (with just cid and bytes)', async () => {
version: data.version,
signature: data.signature,

capabilities: {
...[
{
can: 'store/add',
with: alice.did(),
},
],
},
capabilities: [
{
can: 'store/add',
with: alice.did(),
},
],

notBefore: undefined,
expiration: data.expiration,
Expand Down Expand Up @@ -152,7 +147,7 @@ test('create delegation with attached proof', async () => {
blocks: new Map([[proof.cid.toString(), proof.root]]),
})

assert.containSubset(delegation, {
assert.deepNestedInclude(delegation, {
root,
data,
bytes: root.bytes,
Expand Down Expand Up @@ -261,7 +256,7 @@ test('create delegation chain', async () => {
const { proofs } = invocation
assert.equal(proofs.length, 1)
const [actual] = proofs
assert.containSubset(
assert.deepNestedInclude(
actual,
{
cid: delegation.cid,
Expand Down Expand Up @@ -305,7 +300,7 @@ test('create delegation chain', async () => {
const { proofs } = invocation
assert.equal(proofs.length, 1)
const [actual] = proofs
assert.containSubset(actual, {
assert.deepNestedInclude(actual, {
cid: delegation.cid,
bytes: delegation.bytes,
})
Expand All @@ -321,7 +316,7 @@ test('create delegation chain', async () => {
)

assert.equal(actual.proofs.length, 1)
assert.containSubset(
assert.deepNestedInclude(
actual.proofs[0],
{
cid: proof.cid,
Expand Down
32 changes: 0 additions & 32 deletions packages/core/test/link.spec.js

This file was deleted.

2 changes: 0 additions & 2 deletions packages/core/test/test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import { assert, use } from 'chai'
import subset from 'chai-subset'
use(subset)

export const test = it
export { assert }
8 changes: 4 additions & 4 deletions packages/interface/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@
},
"homepage": "https://github.com/web3-storage/ucanto",
"scripts": {
"typecheck": "tsc --build",
"check": "tsc --build",
"build": "tsc --build"
},
"dependencies": {
"@ipld/dag-ucan": "^4.0.0-beta",
"multiformats": "^9.8.1"
"@ipld/dag-ucan": "^2.0.0",
"multiformats": "^10.0.0"
},
"devDependencies": {
"typescript": "^4.8.3"
"typescript": "^4.8.4"
},
"exports": {
".": {
Expand Down
3 changes: 2 additions & 1 deletion packages/interface/src/capability.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
PrincipalParser,
Signer,
URI,
UCANLink,
Await,
IssuedInvocationView,
UCANOptions,
Expand Down Expand Up @@ -369,7 +370,7 @@ export interface InvalidAudience extends Failure {

export interface UnavailableProof extends Failure {
readonly name: 'UnavailableProof'
readonly link: Link
readonly link: UCANLink
}

export interface Expired extends Failure {
Expand Down
Loading

0 comments on commit 61dc4ca

Please sign in to comment.