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

Install tbdocs for the @web5/api package #251

Merged
merged 6 commits into from
Nov 3, 2023
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
33 changes: 33 additions & 0 deletions .github/workflows/tests-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -107,3 +107,36 @@ jobs:
run: npm run test:browser --ws -- --color
env:
TEST_DWN_URL: http://localhost:3000

tbdocs-reporter:
runs-on: ubuntu-latest
steps:
- name: Checkout source
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2

- name: Set up Node.js
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: 18
registry-url: https://registry.npmjs.org/

- name: Install latest npm
run: npm install -g npm@latest

- name: Install dependencies
run: npm ci

- name: Build all workspace packages
run: npm run build

- name: TBDocs Reporter
id: tbdocs-reporter-protocol
uses: TBD54566975/tbdocs@main
with:
token: ${{ secrets.GITHUB_TOKEN }}
report_changed_scope_only: false
fail_on_error: false
entry_points: |
- file: packages/api/src/index.ts
docsReporter: api-extractor
docsGenerator: typedoc-markdown
6 changes: 6 additions & 0 deletions packages/api/src/did-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@
// didMethodApis: DidMethodApi[];
// cache?: DidResolverCache;
// }

/**
* The DID API is used to create and resolve DIDs.
*
* @beta
*/
export class DidApi {
// private didResolver: DidResolver;
// private methodCreatorMap: Map<string, DidMethodCreator> = new Map();
Expand All @@ -40,8 +46,8 @@
// return this.didResolver;
// }

private agent: Web5Agent;

Check warning on line 49 in packages/api/src/did-api.ts

View workflow job for this annotation

GitHub Actions / tbdocs-reporter

extractor: ae-undocumented

Missing documentation for "agent".
private connectedDid: string;

Check warning on line 50 in packages/api/src/did-api.ts

View workflow job for this annotation

GitHub Actions / tbdocs-reporter

extractor: ae-undocumented

Missing documentation for "connectedDid".

constructor(options: { agent: Web5Agent, connectedDid: string }) {
this.agent = options.agent;
Expand Down
106 changes: 94 additions & 12 deletions packages/api/src/dwn-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,88 +20,170 @@
import { Protocol } from './protocol.js';
import { dataToBlob } from './utils.js';

/**
* Request to setup a protocol with its definitions
*
* @beta
*/
export type ProtocolsConfigureRequest = {
message: Omit<ProtocolsConfigureOptions, 'authorizationSigner'>;
}

/**
* Response for the protocol configure request
*
* @beta
*/
export type ProtocolsConfigureResponse = {
status: UnionMessageReply['status'];
protocol?: Protocol;
}

/**
* Represents each entry on the protocols query reply
*
* @beta
*/
export type ProtocolsQueryReplyEntry = {
descriptor: ProtocolsConfigureDescriptor;
};

/**
* Request to query protocols
*
* @beta
*/
export type ProtocolsQueryRequest = {
from?: string;
message: Omit<ProtocolsQueryOptions, 'authorizationSigner'>
}

/**
* Response with the retrieved protocols
*
* @beta
*/
export type ProtocolsQueryResponse = {
protocols: Protocol[];
status: UnionMessageReply['status'];
}

/**
* Type alias for {@link RecordsWriteRequest}
*
* @beta
*/
export type RecordsCreateRequest = RecordsWriteRequest;

/**
* Type alias for {@link RecordsWriteResponse}
*
* @beta
*/
export type RecordsCreateResponse = RecordsWriteResponse;

/**
* Request to create a record from an existing one (useful for updating an existing record)
*
* @beta
*/
export type RecordsCreateFromRequest = {
author: string;
data: unknown;
message?: Omit<RecordsWriteOptions, 'authorizationSigner'>;
record: Record;
}

/**
* Request to delete a record from the DWN
*
* @beta
*/
export type RecordsDeleteRequest = {
from?: string;
message: Omit<RecordsDeleteOptions, 'authorizationSigner'>;
}

/**
* Response for the delete request
*
* @beta
*/
export type RecordsDeleteResponse = {
status: UnionMessageReply['status'];
};

/**
* Request to query records from the DWN
*
* @beta
*/
export type RecordsQueryRequest = {
/** The from property indicates the DID to query from and return results. */
from?: string;
message: Omit<RecordsQueryOptions, 'authorizationSigner'>;
}

/**
* Response for the query request
*
* @beta
*/
export type RecordsQueryResponse = {
status: UnionMessageReply['status'];
records?: Record[]
};

/**
* Request to read a record from the DWN
*
* @beta
*/
export type RecordsReadRequest = {
/** The from property indicates the DID to read from and return results fro. */
from?: string;
message: Omit<RecordsReadOptions, 'authorizationSigner'>;
}

/**
* Response for the read request
*
* @beta
*/
export type RecordsReadResponse = {
status: UnionMessageReply['status'];
record: Record;
};

/**
* Request to write a record to the DWN
*
* @beta
*/
export type RecordsWriteRequest = {
data: unknown;
message?: Omit<Partial<RecordsWriteOptions>, 'authorizationSigner'>;
store?: boolean;
}

/**
* Response for the write request
*
* @beta
*/
export type RecordsWriteResponse = {
status: UnionMessageReply['status'];
record?: Record
};

/**
* TODO: Document class.
* Interface to interact with DWN Records and Protocols
*
* @beta
*/
export class DwnApi {
private agent: Web5Agent;

Check warning on line 185 in packages/api/src/dwn-api.ts

View workflow job for this annotation

GitHub Actions / tbdocs-reporter

extractor: ae-undocumented

Missing documentation for "agent".
private connectedDid: string;

Check warning on line 186 in packages/api/src/dwn-api.ts

View workflow job for this annotation

GitHub Actions / tbdocs-reporter

extractor: ae-undocumented

Missing documentation for "connectedDid".

constructor(options: { agent: Web5Agent, connectedDid: string }) {
this.agent = options.agent;
Expand All @@ -109,12 +191,12 @@
}

/**
* TODO: Document namespace.
*/
* API to interact with DWN protocols (e.g., `dwn.protocols.configure()`).
*/
get protocols() {
return {
/**
* TODO: Document method.
* Configure method, used to setup a new protocol (or update) with the passed definitions
*/
configure: async (request: ProtocolsConfigureRequest): Promise<ProtocolsConfigureResponse> => {
const agentResponse = await this.agent.processDwnRequest({
Expand All @@ -136,7 +218,7 @@
},

/**
* TODO: Document method.
* Query the available protocols
*/
query: async (request: ProtocolsQueryRequest): Promise<ProtocolsQueryResponse> => {
const agentRequest = {
Expand Down Expand Up @@ -171,19 +253,19 @@
}

/**
* TODO: Document namespace.
* API to interact with DWN records (e.g., `dwn.records.create()`).
*/
get records() {
return {
/**
* TODO: Document method.
* Alias for the `write` method
*/
create: async (request: RecordsCreateRequest): Promise<RecordsCreateResponse> => {
return this.records.write(request);
},

/**
* TODO: Document method.
* Write a record based on an existing one (useful for updating an existing record)
*/
createFrom: async (request: RecordsCreateFromRequest): Promise<RecordsWriteResponse> => {
const { author: inheritedAuthor, ...inheritedProperties } = request.record.toJSON();
Expand Down Expand Up @@ -221,7 +303,7 @@
},

/**
* TODO: Document method.
* Delete a record
*/
delete: async (request: RecordsDeleteRequest): Promise<RecordsDeleteResponse> => {
const agentRequest = {
Expand Down Expand Up @@ -253,7 +335,7 @@
},

/**
* TODO: Document method.
* Query a single or multiple records based on the given filter
*/
query: async (request: RecordsQueryRequest): Promise<RecordsQueryResponse> => {
const agentRequest = {
Expand Down Expand Up @@ -287,7 +369,7 @@
},

/**
* TODO: Document method.
* Read a single record based on the given filter
*/
read: async (request: RecordsReadRequest): Promise<RecordsReadResponse> => {
const agentRequest = {
Expand Down Expand Up @@ -331,7 +413,7 @@
},

/**
* TODO: Document method.
* Writes a record to the DWN
*
* As a convenience, the Record instance returned will cache a copy of the data if the
* data size, in bytes, is less than the DWN 'max data size allowed to be encoded'
Expand Down
29 changes: 27 additions & 2 deletions packages/api/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,33 @@
/**
* Making developing with Web5 components at least 5 times easier to work with.
*
* Web5 consists of the following components:
* - Decentralized Identifiers
* - Verifiable Credentials
* - DWeb Node personal datastores
*
* The SDK sets out to gather the most oft used functionality from all three of
* these pillar technologies to provide a simple library that is as close to
* effortless as possible.
*
* The SDK is currently still under active development, but having entered the
* Tech Preview phase there is now a drive to avoid unnecessary changes unless
* backwards compatibility is provided. Additional functionality will be added
* in the lead up to 1.0 final, and modifications will be made to address
* issues and community feedback.
*
* [Link to GitHub Repo](https://github.com/TBD54566975/web5-js)
*
* @packageDocumentation
*/

export * from './did-api.js';
export * from './dwn-api.js';
export * from './protocol.js';
export * from './record.js';
export * as utils from './utils.js';
export * from './vc-api.js';
export * from './web5.js';
export * from './tech-preview.js';
export * from './tech-preview.js';

import * as utils from './utils.js';
Comment on lines +32 to +33
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Required workaround needed by api-extractor.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@leordev Is this limitation with api-extractor something that is planned to be resolved? Seems unfortunate that we have to modify the source code to satisfy api-extractor being unable to understand valid ES2020 syntax.

export { utils };
29 changes: 29 additions & 0 deletions packages/api/src/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,38 @@
import type { ProtocolsConfigure } from '@tbd54566975/dwn-sdk-js';

// TODO: export ProtocolsConfigureMessage from dwn-sdk-js
/**
* The protocol configure message carries the protocol definition and is used
* to setup the protocol.
*
* @beta
*/
export type ProtocolsConfigureMessage = ProtocolsConfigure['message'];

/**
* Metadata of the protocol
*
* @beta
*/
type ProtocolMetadata = {
author: string;
messageCid?: string;
};

/**
* The Protocol API abstraction class. It's used to represent and retrieve a protocol and
* also to install (send) protocols to other DIDs.
*
* @beta
*/
export class Protocol {
private _agent: Web5Agent;

Check warning on line 30 in packages/api/src/protocol.ts

View workflow job for this annotation

GitHub Actions / tbdocs-reporter

extractor: ae-undocumented

Missing documentation for "_agent".
private _metadata: ProtocolMetadata;
private _protocolsConfigureMessage: ProtocolsConfigureMessage;

/**
* The protocol definition: types, structure and publish status
*/
get definition() {
return this._protocolsConfigureMessage.descriptor.definition;
}
Expand All @@ -23,10 +44,18 @@
this._protocolsConfigureMessage = protocolsConfigureMessage;
}

/**
* Returns the protocol as a JSON object.
*/
toJSON() {
return this._protocolsConfigureMessage;
}

/**
* Sends the protocol to a remote DWN by specifying their DID
* @param target - the DID to send the protocol to
* @returns the status of the send protocols request
*/
async send(target: string) {
const { reply } = await this._agent.sendDwnRequest({
author : this._metadata.author,
Expand Down
Loading
Loading