Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: follow up on the capabilities extract #239

Merged
merged 8 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/access-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
- run: pnpm install
- run: pnpm -r --filter @web3-storage/access-api run lint
- run: pnpm -r --filter @web3-storage/access-api run test
- run: pnpm --filter @web3-storage/access-api -r exec depcheck
- run: pnpm -r --filter @web3-storage/access-api exec depcheck
deploy-staging:
needs: test
if: github.head_ref == 'release-please--branches--main--components--access-api'
Expand Down
4 changes: 2 additions & 2 deletions .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 -r --filter @web3-storage/access run build
- run: pnpm 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
- run: pnpm -r --filter @web3-storage/access exec depcheck
24 changes: 7 additions & 17 deletions .github/workflows/capabilities.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: '@web3-storage/capabilities'
name: Capabilities
env:
CI: true
FORCE_COLOR: 1
Expand All @@ -18,27 +18,17 @@ on:
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 }}
version: 7
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
node-version: 18
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
- run: pnpm run build
- run: pnpm -r --filter @web3-storage/capabilities run lint
- run: pnpm -r --filter @web3-storage/capabilities run test
- run: pnpm -r --filter @web3-storage/capabilities exec depcheck
4 changes: 2 additions & 2 deletions .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 -r --filter @web3-storage/upload-client run build
- run: pnpm 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
- run: pnpm -r --filter @web3-storage/upload-client exec depcheck
11 changes: 7 additions & 4 deletions packages/access-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@
"@sentry/cli": "2.7.0",
"@types/assert": "^1.5.6",
"@types/git-rev-sync": "^2.0.0",
"@types/node": "^18.11.9",
"@types/node": "^18.11.10",
"@types/qrcode": "^1.5.0",
"ava": "^5.1.0",
"better-sqlite3": "8.0.0",
"better-sqlite3": "8.0.1",
"buffer": "^6.0.3",
"dotenv": "^16.0.3",
"esbuild": "^0.15.16",
Expand All @@ -58,10 +58,13 @@
},
"eslintConfig": {
"extends": [
"./node_modules/hd-scripts/eslint/index.js"
"./node_modules/hd-scripts/eslint/preact.js"
],
"parserOptions": {
"project": "./tsconfig.json"
"project": "./tsconfig.json",
"ecmaFeatures": {
"jsx": true
}
},
"globals": {
"VERSION": "readonly",
Expand Down
13 changes: 3 additions & 10 deletions packages/access-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
"exports": {
".": "./src/index.js",
"./agent": "./src/agent.js",
"./capabilities/*": "./src/capabilities/*.js",
"./stores/*": "./src/stores/*.js",
"./types": "./src/types.js",
"./encoding": "./src/encoding.js"
Expand All @@ -44,9 +43,6 @@
"stores/*": [
"dist/src/stores/*"
],
"capabilities/*": [
"dist/src/capabilities/*"
],
"encoding": [
"dist/src/encoding"
]
Expand Down Expand Up @@ -85,7 +81,7 @@
"@types/assert": "^1.5.6",
"@types/inquirer": "^9.0.3",
"@types/mocha": "^10.0.0",
"@types/node": "^18.11.9",
"@types/node": "^18.11.10",
"@types/ws": "^8.5.3",
"@ucanto/server": "^3.0.4",
"assert": "^2.0.0",
Expand All @@ -101,13 +97,10 @@
},
"eslintConfig": {
"extends": [
"./node_modules/hd-scripts/eslint/preact.js"
"./node_modules/hd-scripts/eslint/index.js"
],
"parserOptions": {
"project": "./tsconfig.json",
"ecmaFeatures": {
"jsx": true
}
"project": "./tsconfig.json"
},
"rules": {
"unicorn/prefer-number-properties": "off",
Expand Down
15 changes: 15 additions & 0 deletions packages/access-client/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,21 @@ npm install @web3-storage/access

[API Reference](https://web3-storage.github.io/w3protocol/modules/_web3_storage_access.html)

```js
import { Agent, connection } from '@web3-storage/access/agent'
import * as Encoding from '@web3-storage/access/encoding'
import { StoreConf } from '@web3-storage/access/stores/store-conf'
// for browsers
import { StoreIndexedDB } from '@web3-storage/access/stores/store-indexeddb'

const store = new StoreConf({ profile: 'app' })
if (!(await store.exists())) {
await store.init({})
}

const agent = await Agent.create({ store })
```

## Contributing

Feel free to join in. All welcome. Please [open an issue](https://github.com/web3-storage/w3protocol/issues)!
Expand Down
29 changes: 21 additions & 8 deletions packages/access-client/src/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,19 @@ import {
const HOST = 'https://access.web3.storage'

/**
* @template {string} T
* @param {Ucanto.Principal<T>} principal
* @param {typeof fetch} _fetch
* @param {URL} url
* @param {Ucanto.Transport.Channel<import('./types').Service>} [channel]
* Creates a Ucanto connection for the w3access API
*
* Usage:
*
* ```js
* import { connection } from '@web3-storage/access/agent'
* ```
*
* @template {string} T - DID method
* @param {Ucanto.Principal<T>} principal - w3access API Principal
* @param {typeof fetch} _fetch - fetch implementation to use
* @param {URL} url - w3access API URL
* @param {Ucanto.Transport.Channel<import('./types').Service>} [channel] - Ucanto channel to use
* @returns {Ucanto.ConnectionView<import('./types').Service>}
*/
export function connection(principal, _fetch, url, channel) {
Expand All @@ -51,8 +59,15 @@ export function connection(principal, _fetch, url, channel) {
}

/**
* @template {Ucanto.Signer} T
* Agent
*
* Usage:
*
* ```js
* import { Agent } from '@web3-storage/access/agent'
* ```
*
* @template {Ucanto.Signer} T - Ucanto Signer ie. ed25519, RSA or others
*/
export class Agent {
/** @type {Ucanto.Principal<"key">|undefined} */
Expand Down Expand Up @@ -452,8 +467,6 @@ export class Agent {
/**
* Invoke and execute the given capability on the Access service connection
*
* Sugar for :
*
* ```js
*
* await agent.invokeAndExecute(Space.recover, {
Expand Down
2 changes: 1 addition & 1 deletion packages/access-client/src/encoding.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Encoding utilities
*
* These can be imported directly with:
* It is recommended that you import directly with:
* ```js
* import * as Encoding from '@web3-storage/access/encoding'
*
Expand Down
2 changes: 0 additions & 2 deletions packages/access-client/src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/* 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 Encoding from './encoding.js'
export { StoreConf } from './stores/store-conf.js'
Expand Down
8 changes: 7 additions & 1 deletion packages/access-client/src/stores/store-conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ import * as Ucanto from '@ucanto/interface'
*/

/**
* Store implementation with "conf"
* Store implementation with "[conf](https://github.com/sindresorhus/conf)"
*
* Usage:
*
* ```js
* import { StoreConf } from '@web3-storage/access/stores/store-conf'
* ```
*
* @implements {Store}
*/
Expand Down
6 changes: 6 additions & 0 deletions packages/access-client/src/stores/store-indexeddb.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ const DATA_ID = 1
/**
* Store implementation for the browser.
*
* Usage:
*
* ```js
* import { StoreIndexedDB } from '@web3-storage/access/stores/store-indexeddb'
* ```
*
* @implements {Store}
*/
export class StoreIndexedDB {
Expand Down
2 changes: 1 addition & 1 deletion packages/access-ws/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"@cloudflare/workers-types": "^3.18.0",
"@sentry/cli": "2.7.0",
"@types/git-rev-sync": "^2.0.0",
"@types/node": "^18.11.9",
"@types/node": "^18.11.10",
"ava": "^5.1.0",
"buffer": "^6.0.3",
"dotenv": "^16.0.3",
Expand Down
45 changes: 25 additions & 20 deletions packages/capabilities/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,39 @@
"scripts": {
"lint": "tsc && eslint '**/*.{js,ts}' && prettier --check '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore",
"build": "tsc --build",
"test": "pnpm -r --filter @web3-storage/capabilities run build && npm run test:node && npm run test:browser",
"test:node": "mocha 'test/**/!(*.browser).test.js' -n experimental-vm-modules -n no-warnings",
"test:browser": "playwright-test 'test/**/!(*.node).test.js'",
"testw": "watch 'pnpm test' src test --interval 1",
"test": "pnpm run test:node && pnpm run test:browser",
"test:node": "mocha 'test/**/*.test.js' -n experimental-vm-modules -n no-warnings",
"test:browser": "playwright-test",
"testw": "watch 'pnpm test:node' src test --interval 1",
"rc": "npm version prerelease --preid rc"
},
"exports": {
".": "./src/index.js",
"./types": "./dist/src/capabilities/types.d.ts",
"./*": "./src/capabilities/*.js"
"./types": "./dist/src/types.d.ts",
"./*": "./src/*.js"
},
"typesVersions": {
"*": {
"space": [
"dist/src/capabilities/space"
"dist/src/space"
],
"store": [
"dist/src/capabilities/store"
"dist/src/store"
],
"types": [
"dist/src/capabilities/types"
"dist/src/types"
],
"top": [
"dist/src/capabilities/top"
"dist/src/top"
],
"upload": [
"dist/src/capabilities/upload"
"dist/src/upload"
],
"utils": [
"dist/src/capabilities/utils"
"dist/src/utils"
],
"voucher": [
"dist/src/capabilities/voucher"
"dist/src/voucher"
]
}
},
Expand All @@ -57,21 +57,16 @@
"dist/src/**/*.d.ts.map"
],
"dependencies": {
"@ipld/car": "^5.0.1",
"@ipld/dag-ucan": "^2.0.1",
"@ucanto/client": "^3.0.2",
"@ucanto/core": "^3.0.2",
"@ucanto/interface": "^3.0.1",
"@ucanto/principal": "^3.0.1",
"@ucanto/server": "^3.0.4",
"@ucanto/transport": "^3.0.2",
"@ucanto/validator": "^3.0.4"
},
"devDependencies": {
"@types/assert": "^1.5.6",
"@types/mocha": "^10.0.0",
"@types/node": "^18.11.9",
"@web-std/fetch": "^4.1.0",
"@types/node": "^18.11.10",
"assert": "^2.0.0",
"hd-scripts": "^3.0.2",
"mocha": "^10.1.0",
Expand All @@ -81,7 +76,7 @@
},
"eslintConfig": {
"extends": [
"./node_modules/hd-scripts/eslint/preact.js"
"./node_modules/hd-scripts/eslint/index.js"
],
"parserOptions": {
"project": "./tsconfig.json"
Expand All @@ -98,5 +93,15 @@
"dist",
"coverage"
]
},
"depcheck": {
"specials": [
"bin"
],
"ignores": [
"@types/*",
"hd-scripts",
"assert"
]
}
}
Loading