Readonly
endpointAddress of a p2panda node that we can connect to.
Readonly
clientA GraphQL client connected to the configured endpoint.
Private
#schemaGlobally configured schema id which is used as a default for all requests.
Private
#keyGlobally configured key pair which is used as a default for all requests.
Returns currently configured schema id.
Throws if no schema id is configured.
SchemaId instance
Set a fixed key pair for this session, which will be used by methods
unless a different key pair is configured through their options
parameters.
This does not check the integrity or type of the supplied key pair!
key pair instance generated using the KeyPair
class.
Session instance
Return arguments for constructing the next entry given public key and document view id.
public key of the author
Optional
viewId: DocumentViewIdoptional document view id
NextArgs arguments used to create a new entry
Publish an encoded entry and operation.
This method returns the "local" document view id, which represents the latest version of the document we've created, updated or deleted.
It is "local" because it is the "latest version" from our perspective. Concurrent updates through other peers might have happend but we didn't know about them in the moment we've published our operation.
If concurrent edits by other peers should also be referred to (as is often the case) then the document view id should be accessed via the GraphQL client API.
encoded and signed entry, represented as hexadecimal string
encoded CBOR operation, represented as hexadecimal string
DocumentViewId - local document view id
Creates a new document with the given fields and matching schema id.
Document id of the document we've created
const endpoint = 'http://localhost:2020/graphql';
const keyPair = new KeyPair();
const schemaId = 'chat_00206394434d78553bd064c8ea9a61d2b9622826909966ae895eb1c8b692b335d919';
const fields = {
message: 'ahoy'
};
await new Session(endpoint)
.setKeyPair(keyPair)
.create(fields, { schemaId });
Updates a document with the given fields and matching schema id.
The document to be updated is identified by the previous
parameter which contains
the most recent known document view id.
data to publish with the new entry, needs to match schema
array or string of operation ids identifying the tips of all currently un-merged branches in the document graph
Optional
options: Partial<Options>overrides globally set options for this method call
Document view id, pointing at the exact version of the document we've just updated
const endpoint = 'http://localhost:2020/graphql';
const keyPair = new KeyPair();
const schemaId = 'chat_00206394434d78553bd064c8ea9a61d2b9622826909966ae895eb1c8b692b335d919';
const session = new Session(endpoint)
.setKeyPair(keyPair)
.setSchemaId(schemaId);
// Create a new document first
const viewId = await session.create({
message: 'ahoy!'
});
// Use the `viewId` to point our update at the document we've just created
await session.update({
message: 'ahoy, my friend!'
}, viewId);
Deletes a document.
The document to be deleted is identified by the previous
parameter
which contains the most recent known document view id.
array or string of operation ids identifying the tips of all currently un-merged branches in the document graph
Optional
options: Partial<Options>overrides globally set options for this method call
Document view id, pointing at the exact version of the document we've just deleted
const endpoint = 'http://localhost:2020/graphql';
const keyPair = new KeyPair();
const schemaId = 'chat_00206394434d78553bd064c8ea9a61d2b9622826909966ae895eb1c8b692b335d919';
const session = new Session(endpoint)
.setKeyPair(keyPair)
.setSchemaId(schemaId);
// Create a new document first
const viewId = await session.create({
message: 'ahoy!'
});
// Use the `viewId` to point our deletion at the document we've just created
await session.delete(viewId);
Publish a blob.
The blob byte array is split into 256kb long pieces which are each published
individually, following this the blob document itself is published. Included
metadata is mime_type
[str] and length
[int] representing the complete
byte length of the blob file.
blob data to be published
Optional
options: Partial<Options>overrides globally set options for this method call
Document id of the blob we've created
const endpoint = 'http://localhost:2020/graphql';
const keyPair = new KeyPair();
const session = await new Session(endpoint)
.setKeyPair(keyPair)
.create(fields, { schemaId });
const input = document.querySelector('input');
const blob = input.files[0];
await session.createBlob(blob);
Generated using TypeDoc
Communicate with the p2panda network through a
Session
instance.Session
provides a high-level interface to create data in the p2panda network by creating, updating and deleting documents following data schemas. It also provides a low-level API for creating entries on the Bamboo append-only log structure.A session is configured with the URL of a p2panda node, which may be running locally or on a remote machine. It is possible to set a fixed key pair and/or data schema for a session by calling
setKeyPair()
andsetSchemaId()
or you can also configure these through theoptions
parameter of methods.