Skip to content

Commit

Permalink
chore: split packages/access-client/src/capabilities to new package @…
Browse files Browse the repository at this point in the history
…web3-storage/capabilities (#218)

Motivation:
* #80

To do:
* [x] initial package split
* [x] remove capabilities dir from packages/access-client and fix
imports in access-client
* [x] fix imports from other packages that were importing from
access-client/capabilities
* [x] consider splitting to `capabilities/{service}/types` not
`capabilities/types`
* decided not to unless requested (makes exports map even more
complicated, can do later)
* [x] GH actions should run tests on packages/capabilities
* [x] .github/workflows/release.yml does npm/docs jobs if paths_released
contains packages/capabilities

Co-authored-by: Irakli Gozalishvili <contact@gozala.io>
  • Loading branch information
gobengo and Gozala authored Nov 30, 2022
1 parent 0dd1633 commit 50a50cf
Show file tree
Hide file tree
Showing 53 changed files with 346 additions and 72 deletions.
1 change: 1 addition & 0 deletions .github/release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"packages": {
"packages/access-client": {},
"packages/access-api": {},
"packages/capabilities": {},
"packages/upload-client": {},
"packages/wallet": {}
}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/access-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
node-version: 18
cache: 'pnpm'
- run: pnpm install
- run: pnpm run build
- run: pnpm -r --filter @web3-storage/access run build
- run: pnpm -r --filter @web3-storage/access run lint
- run: pnpm -r --filter @web3-storage/access run test
- run: pnpm --filter @web3-storage/access -r exec depcheck
44 changes: 44 additions & 0 deletions .github/workflows/capabilities.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: '@web3-storage/capabilities'
env:
CI: true
FORCE_COLOR: 1
on:
push:
branches:
- main
paths:
- 'packages/capabilities/**'
- '.github/workflows/capabilities.yml'
- 'pnpm-lock.yaml'
pull_request:
paths:
- 'packages/capabilities/**'
- '.github/workflows/capabilities.yml'
- 'pnpm-lock.yaml'
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
pnpm-version:
- 7
node-version:
- 18
package:
- capabilities
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2.2.3
with:
version: ${{ matrix.pnpm-version }}
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
- run: pnpm install
- name: Typecheck
uses: gozala/typescript-error-reporter-action@v1.0.8
with:
project: packages/${{matrix.package}}/tsconfig.json
- run: pnpm -r --filter @web3-storage/${{matrix.package}} run lint
- run: pnpm -r --filter @web3-storage/${{matrix.package}} run test
10 changes: 8 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ jobs:
secrets: inherit
npm:
needs: release
if: contains(fromJson(needs.release.outputs.paths_released), 'packages/access-client') || contains(fromJson(needs.release.outputs.paths_released), 'packages/upload-client')
if: |
contains(fromJson(needs.release.outputs.paths_released), 'packages/access-client') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/capabilities') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/upload-client')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -56,5 +59,8 @@ jobs:
NODE_AUTH_TOKEN: ${{secrets.NPM_TOKEN}}
docs:
needs: release
if: contains(fromJson(needs.release.outputs.paths_released), 'packages/access-client') || contains(fromJson(needs.release.outputs.paths_released), 'packages/upload-client')
if: |
contains(fromJson(needs.release.outputs.paths_released), 'packages/access-client') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/capabilities') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/upload-client')
uses: './.github/workflows/reusable-deploy-docs.yml'
2 changes: 1 addition & 1 deletion .github/workflows/upload-client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
node-version: 18
cache: 'pnpm'
- run: pnpm install
- run: pnpm run build
- run: pnpm -r --filter @web3-storage/upload-client run build
- run: pnpm -r --filter @web3-storage/upload-client run lint
- run: pnpm -r --filter @web3-storage/upload-client run test
- run: pnpm --filter @web3-storage/access-api -r exec depcheck
1 change: 1 addition & 0 deletions packages/access-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"@ucanto/server": "^3.0.4",
"@ucanto/transport": "^3.0.2",
"@web3-storage/access": "workspace:^",
"@web3-storage/capabilities": "workspace:^",
"@web3-storage/worker-utils": "0.4.3-dev",
"p-retry": "^5.1.2",
"preact": "^10.11.3",
Expand Down
6 changes: 3 additions & 3 deletions packages/access-api/src/kvs/spaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export class Spaces {
}

/**
* @param {import('@web3-storage/access/capabilities/types').VoucherRedeem} capability
* @param {Ucanto.Invocation<import('@web3-storage/access/capabilities/types').VoucherRedeem>} invocation
* @param {import('@web3-storage/capabilities/types').VoucherRedeem} capability
* @param {Ucanto.Invocation<import('@web3-storage/capabilities/types').VoucherRedeem>} invocation
*/
async create(capability, invocation) {
await this.db.insert({
Expand Down Expand Up @@ -110,7 +110,7 @@ export class Spaces {
return
}

return /** @type {import('@web3-storage/access/types').EncodedDelegation<[import('@web3-storage/access/types').Top]>[]} */ (
return /** @type {import('@web3-storage/access/types').EncodedDelegation<[import('@web3-storage/capabilities/types').Top]>[]} */ (
r
)
}
Expand Down
5 changes: 2 additions & 3 deletions packages/access-api/src/service/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import * as Server from '@ucanto/server'
import { Failure } from '@ucanto/server'
import * as Space from '@web3-storage/access/capabilities/space'
import * as Space from '@web3-storage/capabilities/space'
import { voucherClaimProvider } from './voucher-claim.js'
import { voucherRedeemProvider } from './voucher-redeem.js'
import * as DID from '@ipld/dag-ucan/did'
import {
delegationToString,
stringToDelegation,
} from '@web3-storage/access/encoding'
import { top } from '@web3-storage/access/capabilities/top'

/**
* @param {import('../bindings').RouteContext} ctx
Expand Down Expand Up @@ -52,7 +51,7 @@ export function service(ctx) {
const results = []
for (const e of encoded) {
const proof = await stringToDelegation(e)
const del = await top.delegate({
const del = await Space.top.delegate({
audience: invocation.issuer,
issuer: ctx.signer,
with: proof.capabilities[0].with,
Expand Down
2 changes: 1 addition & 1 deletion packages/access-api/src/service/voucher-claim.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Server from '@ucanto/server'
import * as Voucher from '@web3-storage/access/capabilities/voucher'
import * as Voucher from '@web3-storage/capabilities/voucher'
import { delegationToString } from '@web3-storage/access/encoding'

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/access-api/src/service/voucher-redeem.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Server from '@ucanto/server'
import * as Voucher from '@web3-storage/access/capabilities/voucher'
import * as Voucher from '@web3-storage/capabilities/voucher'
import { Delegation } from '@ucanto/core'
import { Failure } from '@ucanto/server'
/**
Expand Down
2 changes: 1 addition & 1 deletion packages/access-api/src/utils/html.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class HtmlResponse extends Response {
/**
*
* @param {object} param0
* @param {Ucanto.Delegation<[import('@web3-storage/access/capabilities/types').VoucherClaim]> | Ucanto.Delegation<[import('@web3-storage/access/capabilities/types').SpaceRecover]>} param0.delegation
* @param {Ucanto.Delegation<[import('@web3-storage/capabilities/types').VoucherClaim]> | Ucanto.Delegation<[import('@web3-storage/capabilities/types').SpaceRecover]>} param0.delegation
* @param {string} param0.ucan
* @param {string} param0.qrcode
*/
Expand Down
10 changes: 5 additions & 5 deletions packages/access-api/test/account-recover.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as Space from '@web3-storage/access/capabilities/space'
import * as Space from '@web3-storage/capabilities/space'
import { stringToDelegation } from '@web3-storage/access/encoding'
import pWaitFor from 'p-wait-for'
import { context, test } from './helpers/context.js'
Expand Down Expand Up @@ -53,7 +53,7 @@ test('should return space/recover', async (t) => {

const url = new URL(inv)
const encoded =
/** @type {import('@web3-storage/access/types').EncodedDelegation<[import('@web3-storage/access/capabilities/types').SpaceRecover]>} */ (
/** @type {import('@web3-storage/access/types').EncodedDelegation<[import('@web3-storage/capabilities/types').SpaceRecover]>} */ (
url.searchParams.get('ucan')
)

Expand All @@ -70,7 +70,7 @@ test('should return space/recover', async (t) => {
// @ts-ignore
const validations = new Validations(await mf.getKVNamespace('VALIDATIONS'))
const recoverEncoded =
/** @type {import('@web3-storage/access/types').EncodedDelegation<[import('@web3-storage/access/capabilities/types').SpaceRecover]>} */ (
/** @type {import('@web3-storage/access/types').EncodedDelegation<[import('@web3-storage/capabilities/types').SpaceRecover]>} */ (
await validations.get(issuer.did())
)

Expand All @@ -94,7 +94,7 @@ test('should return space/recover', async (t) => {
const data = JSON.parse(event.data)

const encoded =
/** @type {import('@web3-storage/access/types').EncodedDelegation<[import('@web3-storage/access/capabilities/types').SpaceRecover]>} */ (
/** @type {import('@web3-storage/access/types').EncodedDelegation<[import('@web3-storage/capabilities/types').SpaceRecover]>} */ (
data.delegation
)

Expand Down Expand Up @@ -141,7 +141,7 @@ test('should invoke space/recover and get space delegation', async (t) => {

const url = new URL(inv)
const encoded =
/** @type {import('@web3-storage/access/types').EncodedDelegation<[import('@web3-storage/access/capabilities/types').SpaceRecover]>} */ (
/** @type {import('@web3-storage/access/types').EncodedDelegation<[import('@web3-storage/capabilities/types').SpaceRecover]>} */ (
url.searchParams.get('ucan')
)

Expand Down
7 changes: 3 additions & 4 deletions packages/access-api/test/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import * as UCAN from '@ipld/dag-ucan'
// eslint-disable-next-line no-unused-vars
import * as Types from '@ucanto/interface'
import * as Top from '@web3-storage/access/capabilities/top'
import * as Voucher from '@web3-storage/access/capabilities/voucher'
import * as Voucher from '@web3-storage/capabilities/voucher'
import { stringToDelegation } from '@web3-storage/access/encoding'
import { Signer } from '@ucanto/principal/ed25519'

Expand Down Expand Up @@ -40,7 +39,7 @@ export async function createSpace(issuer, service, conn, email) {
service: service.did(),
},
proofs: [
await Top.top.delegate({
await Voucher.top.delegate({
issuer: space,
audience: issuer,
with: space.did(),
Expand All @@ -67,7 +66,7 @@ export async function createSpace(issuer, service, conn, email) {
},
proofs: [
delegation,
await Top.top.delegate({
await Voucher.top.delegate({
issuer: space,
audience: service,
with: space.did(),
Expand Down
2 changes: 1 addition & 1 deletion packages/access-api/test/voucher-claim.test.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Delegation } from '@ucanto/core'
import * as Voucher from '@web3-storage/access/capabilities/voucher'
import * as Voucher from '@web3-storage/capabilities/voucher'
import { stringToDelegation } from '@web3-storage/access/encoding'
import { context, test } from './helpers/context.js'

Expand Down
7 changes: 3 additions & 4 deletions packages/access-api/test/voucher-redeem.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable unicorn/prefer-number-properties */
import * as Top from '@web3-storage/access/capabilities/top'
import * as Voucher from '@web3-storage/access/capabilities/voucher'
import * as Voucher from '@web3-storage/capabilities/voucher'
import { stringToDelegation } from '@web3-storage/access/encoding'
import { context, test } from './helpers/context.js'
import { createSpace } from './helpers/utils.js'
Expand All @@ -26,7 +25,7 @@ test('should return voucher/redeem', async (t) => {
service: service.did(),
},
proofs: [
await Top.top.delegate({
await Voucher.top.delegate({
issuer: space,
audience: issuer,
with: space.did(),
Expand Down Expand Up @@ -57,7 +56,7 @@ test('should return voucher/redeem', async (t) => {
},
proofs: [
delegation,
await Top.top.delegate({
await Voucher.top.delegate({
issuer: space,
audience: service,
with: space.did(),
Expand Down
2 changes: 1 addition & 1 deletion packages/access-api/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
},
"include": ["src", "scripts", "test", "package.json", "sql"],
"exclude": ["**/node_modules/**"],
"references": [{ "path": "../access-client" }]
"references": [{ "path": "../access-client" }, { "path": "../capabilities" }]
}
1 change: 1 addition & 0 deletions packages/access-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"@ucanto/principal": "^3.0.1",
"@ucanto/transport": "^3.0.2",
"@ucanto/validator": "^3.0.4",
"@web3-storage/capabilities": "workspace:^",
"bigint-mod-arith": "^3.1.2",
"conf": "^10.2.0",
"inquirer": "^9.1.4",
Expand Down
7 changes: 3 additions & 4 deletions packages/access-client/src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ import * as CBOR from '@ucanto/transport/cbor'
import * as HTTP from '@ucanto/transport/http'
import { URI } from '@ucanto/validator'
import { Peer } from './awake/peer.js'
import * as Space from './capabilities/space.js'
import * as Voucher from './capabilities/voucher.js'
import { top as Top } from './capabilities/top.js'
import * as Space from '@web3-storage/capabilities/space'
import * as Voucher from '@web3-storage/capabilities/voucher'
import { stringToDelegation } from './encoding.js'
import { Websocket, AbortError } from './utils/ws.js'
import { Signer } from '@ucanto/principal/ed25519'
Expand Down Expand Up @@ -225,7 +224,7 @@ export class Agent {
*/
async createSpace(name) {
const signer = await Signer.generate()
const proof = await Top.delegate({
const proof = await Space.top.delegate({
issuer: signer,
audience: this.issuer,
with: signer.did(),
Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/src/delegations.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-ignore
// eslint-disable-next-line no-unused-vars
import * as Ucanto from '@ucanto/interface'
import { canDelegateAbility } from './capabilities/utils.js'
import { canDelegateAbility } from '@web3-storage/capabilities/utils'

/**
*
Expand Down
7 changes: 2 additions & 5 deletions packages/access-client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
/* eslint-disable jsdoc/check-tag-names */
export * from './agent.js'

export { Space, Store, Top, Upload, Voucher } from '@web3-storage/capabilities'

// Workaround for typedoc until 0.24 support export maps
export * as Space from './capabilities/space.js'
export * as Top from './capabilities/top.js'
export * as Store from './capabilities/store.js'
export * as Upload from './capabilities/upload.js'
export * as Voucher from './capabilities/voucher.js'
export * as Encoding from './encoding.js'
export { StoreConf } from './stores/store-conf.js'
export { StoreIndexedDB } from './stores/store-indexeddb.js'
7 changes: 4 additions & 3 deletions packages/access-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,15 @@ import type {
SpaceInfo,
SpaceRecover,
SpaceRecoverValidation,
VoucherClaim,
VoucherRedeem,
Top,
} from './capabilities/types'
import { VoucherClaim, VoucherRedeem } from './capabilities/types.js'
} from '@web3-storage/capabilities/types'
import { IStore } from './stores/types.js'
import type { SetRequired } from 'type-fest'

// export other types
export * from './capabilities/types.js'
export * from '@web3-storage/capabilities/types'
export * from './stores/types.js'

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/test/agent.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from 'assert'
import { URI } from '@ucanto/validator'
import { Agent } from '../src/agent.js'
import { StoreMemory } from '../src/stores/store-memory.js'
import * as Space from '../src/capabilities/space.js'
import * as Space from '@web3-storage/capabilities/space'
import { createServer } from './helpers/utils.js'
import * as fixtures from './helpers/fixtures.js'

Expand Down
7 changes: 0 additions & 7 deletions packages/access-client/test/capabilities.test.js

This file was deleted.

2 changes: 1 addition & 1 deletion packages/access-client/test/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import * as Ucanto from '@ucanto/interface'
import { parseLink } from '@ucanto/core'
import * as Server from '@ucanto/server'
import * as Space from '../../src/capabilities/space.js'
import * as Space from '@web3-storage/capabilities/space'
import * as CAR from '@ucanto/transport/car'
import * as CBOR from '@ucanto/transport/cbor'
import { service } from './fixtures.js'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import assert from 'assert'
import { top } from '../../src/capabilities/top.js'
import { top } from '@web3-storage/capabilities/top'
import { StoreIndexedDB } from '../../src/stores/store-indexeddb.js'
import { Signer } from '@ucanto/principal/ed25519'

Expand Down
3 changes: 2 additions & 1 deletion packages/access-client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
"emitDeclarationOnly": true
},
"include": ["src", "scripts", "test", "package.json"],
"exclude": ["**/node_modules/**"]
"exclude": ["**/node_modules/**"],
"references": [{ "path": "../capabilities" }]
}
Loading

0 comments on commit 50a50cf

Please sign in to comment.