0.1.19 • Published 5 years ago
@cbj/ceramic-append-collection v0.1.19
Ceramic Append Collection
This guide describes how to create, update, and query an Append Collection based on CIP-85.
Installation
npm install @cbj/ceramic-append-collectionBasic Use
import { AppendCollection } from '@cbj/ceramic-append-collection'
const collection = await AppendCollection.create(ceramic, { sliceMaxItems })
/* or */
const collection = await AppendCollection.load(ceramic, streamId)
const streamId = collection.id.toString()
const cursor = await collection.insert({ foo: 'bar' })
const cursor2 = await collection.insert({ foo: 'baz' })
const item1 = await collection.getItem(cursor)
const item2 = await collection.getItem(cursor2)
console.log(item1.value) // { foo: 'bar' }
console.log(item2.value) // { foo: 'baz' }
let firstItems = await collection.getFirstN(1)
console.log(firstItems) // [ { foo: 'bar' } ]
firstItems = await collection.getFirstN(2)
console.log(firstItems) // [ { foo: 'baz' }, { foo: 'baz' } ]
let lastItems = await collection.getLastN(1)
console.log(lastItems) // [ { foo: 'baz' } ]
lastItems = await collection.getLastN(2)
console.log(lastItems) // [ { foo: 'baz' }, { foo: 'bar' } ]
await collection.remove(item1.cursor)
firstItems = await collection.getFirstN(2)
console.log(firstItems) // [ { foo: 'baz' } ]
await collection.remove(item2.cursor)
firstItems = await collection.getFirstN(2)
console.log(firstItems) // []Query a Collection
getFirstN(N: number, fromCursor?: Cursor | null): Promise<Item[]>;
getLastN(N: number, fromCursor?: Cursor | null): Promise<Item[]>;
getItem(cursor: Cursor): Promise<Item | null>;
getHeadCursor(): Promise<Cursor | null>;
getTailCursor(): Promise<Cursor | null>;
getNextCursor(cursor: Cursor): Promise<Cursor | null>;
getPreviousCursor(cursor: Cursor): Promise<Cursor | null>;
getSlicesCount(): Promise<number>;0.1.18
5 years ago
0.1.19
5 years ago
0.1.17
5 years ago
0.1.14
5 years ago
0.1.15
5 years ago
0.1.16
5 years ago
0.1.10
5 years ago
0.1.11
5 years ago
0.1.12
5 years ago
0.1.13
5 years ago
0.1.9
5 years ago
0.1.8
5 years ago
0.1.7
5 years ago
0.1.6
5 years ago
0.1.5
5 years ago
0.1.4
5 years ago
0.1.3
5 years ago
0.1.2
5 years ago
0.1.1
5 years ago
0.1.0
5 years ago