Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@atek-cloud/adb-api

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@atek-cloud/adb-api

Atek DB API

  • 1.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Atek Database API

atek.cloud/adb-api

npm install @atek-cloud/adb-api
import adb from '@atek-cloud/adb-api'
import cats from 'example-cats-table'

// get or create a database under the 'mydb' alias
const db = adb.db('mydb')

// use the cats table
await cats(db).create({id: 'kit', name: 'Kit'})
await cats(db).list() // => {records: [{key: 'kit', value: {id: 'kit', name: 'Kit', createdAt: '2021-09-07T01:06:07.487Z'}}]}
await cats(db).get('kit') // => {key: 'kit', value: {id: 'kit', name: 'Kit', createdAt: '2021-09-07T01:06:07.487Z'}}
await cats(db).put('kit', {id: 'kit', name: 'Kitty'})
await cats(db).delete('kit')

See The Atek DB Guide to learn how to use ADB.

Default export

NameType
.apiAdbApi & AtekRpcClient
.db(dbId: string | DbSettings, opts?: DbSettings) => AdbDatabase

Use the .db() method to create AdbDatabase instances. You may pass a Hypercore 64-character hex-string key or an arbitrary string (which will be a local alias).

import adb from '@atek-cloud/adb-api'

// get or create a database under the 'mydb' alias
// - the 'mydb' alias will be stored under this application for easy future access
const db = adb.db('mydb')

// get a database under its Hypercore key
// - if the database does not exist locally, its content will be fetched from the p2p network
const db2 = adb.db('97396e81e407e5ae7a64b375cc54c1fc1a0d417a5a72e2169b5377506e1e3163')

The .api is the RPC interface which will be used by .db().

Functions

createClient

createClient(): AdbApi & AtekRpcClient

Returns

AdbApi & AtekRpcClient

Use this method to create additional instances of the RPC interface, if needed.

import { createClient } from '@atek-cloud/adb-api'

const adbApi = createClient()
// adbApi is another instance of the default export's adb.api

createServer

createServer(handlers): AtekRpcServer

Parameters
NameType
handlersany
Returns

AtekRpcServer

Use this method to create an ADB server API. You'll only need this if you're creating an alternative implementation to the main ADB.


defineTable

defineTable<T>(tableId, desc): (db: AdbDatabase) => any

Type parameters
NameType
Textends object
Parameters
NameType
tableIdstring
descTableSettings
Returns

fn

▸ (db): AdbTable<T>

Parameters
NameType
dbAdbDatabase
Returns

AdbDatabase

Creates a table API which can be called on databases:

import adb, { defineTable } from '@atek-cloud/adb-api`

// provide a typescript interface for the records
interface CatRecord {
  id: string
  name: string
  createdAt: string
}

// define the cats table
const catsTable = defineTable<CatRecord>({
  id: 'example.com/cats',
  schema: {
    type: 'object',
    required: ['id', 'name']
    properties: {
      id: {type: 'string'},
      name: {type: 'string'},
      createdAt: {type: 'string', format: 'date-time'}
    }
  },
  templates: {
    table: {
      title: 'Cats',
      description: 'A table for tracking my cats'
    },
    record: {
      key: '{{/id}}',
      title: 'Kitty: {{/name}}'
    }
  }
})

// use the cats table
const db = adb.db('mydb')
await cats(db).create({id: 'kit', name: 'Kit'})
await cats(db).list() // => {records: [{key: 'kit', value: {id: 'kit', name: 'Kit', createdAt: '2021-09-07T01:06:07.487Z'}}]}
await cats(db).get('kit') // => {key: 'kit', value: {id: 'kit', name: 'Kit', createdAt: '2021-09-07T01:06:07.487Z'}}
await cats(db).put('kit', {id: 'kit', name: 'Kitty'})
await cats(db).delete('kit')

Class: AdbDatabase

  • Properties
    • isReady
    • api
    • dbId
  • Methods
    • describe
    • define
    • list
    • get
    • create
    • put
    • delete
    • diff
    • getBlob
    • putBlob
    • delBlob

Constructor

new AdbDatabase(api, dbId, opts?)

Parameters
NameType
apiAdbApi
dbIdstring
opts?DbSettings

Properties

isReady

isReady: undefined | Promise<any>


api

api: AdbApi


dbId

dbId: string

Methods

describe

describe(): Promise<DbDescription>

desc Get metadata and information about the database.

Returns

Promise<DbDescription>


define

define(tableId, desc): Promise<TableDescription>

desc Register a table's schema and metadata.

Parameters
NameType
tableIdstring
descTableSettings
Returns

Promise<TableDescription>


list

list(tableId, opts?): Promise<Object>

desc List records in a table.

Parameters
NameType
tableIdstring
opts?ListOpts
Returns

Promise<Object>


get

get(tableId, key): Promise<Record<object>>

desc Get a record in a table.

Parameters
NameType
tableIdstring
keystring
Returns

Promise<Record<object>>


create

create(tableId, value, blobs?): Promise<Record<object>>

desc Add a record to a table.

Parameters
NameType
tableIdstring
valueobject
blobs?BlobMap
Returns

Promise<Record<object>>


put

put(tableId, key, value): Promise<Record<object>>

desc Write a record to a table.

Parameters
NameType
tableIdstring
keystring
valueobject
Returns

Promise<Record<object>>


delete

delete(tableId, key): Promise<void>

desc Delete a record from a table.

Parameters
NameType
tableIdstring
keystring
Returns

Promise<void>


diff

diff(opts): Promise<Diff[]>

desc Enumerate the differences between two versions of the database.

Parameters
NameType
optsObject
opts.leftnumber
opts.right?number
opts.tableIds?string[]
Returns

Promise<Diff[]>


getBlob

getBlob(tableId, key, blobName): Promise<Blob>

desc Get a blob of a record.

Parameters
NameType
tableIdstring
keystring
blobNamestring
Returns

Promise<Blob>


putBlob

putBlob(tableId, key, blobName, blobValue): Promise<void>

desc Write a blob of a record.

Parameters
NameType
tableIdstring
keystring
blobNamestring
blobValueBlobDesc
Returns

Promise<void>


delBlob

delBlob(tableId, key, blobName): Promise<void>

desc Delete a blob of a record.

Parameters
NameType
tableIdstring
keystring
blobNamestring
Returns

Promise<void>

Class: AdbTable<T>

  • Properties
    • isReady
    • db
    • tableId
    • tableDesc
  • Methods
    • list
    • get
    • create
    • put
    • delete
    • diff
    • getBlob
    • putBlob
    • delBlob

Constructor

new AdbTable<T>(db, tableId, tableDesc)

Type parameters
NameType
Textends object
Parameters
NameType
dbAdbDatabase
tableIdstring
tableDescTableSettings

Properties

isReady

isReady: Promise<any>


db

db: AdbDatabase


tableId

tableId: string


tableDesc

tableDesc: TableSettings

Methods

list

list(opts?): Promise<Object>

desc List records in the table.

Parameters
NameType
opts?ListOpts
Returns

Promise<Object>


get

get(key): Promise<Record<T>>

desc Get a record in the table.

Parameters
NameType
keystring
Returns

Promise<Record<T>>


create

create(value, blobs?): Promise<Record<T>>

desc Add a record to the table.

Parameters
NameType
valueT
blobs?BlobMap
Returns

Promise<Record<T>>


put

put(key, value): Promise<Record<T>>

desc Write a record to the table.

Parameters
NameType
keystring
valueT
Returns

Promise<Record<T>>


delete

delete(key): Promise<void>

desc Delete a record from the table.

Parameters
NameType
keystring
Returns

Promise<void>


diff

diff(opts): Promise<Diff[]>

desc Enumerate the differences between two versions of the database.

Parameters
NameType
optsObject
opts.leftnumber
opts.right?number
Returns

Promise<Diff[]>


getBlob

getBlob(key, blobName): Promise<Blob>

desc Get a blob of a record.

Parameters
NameType
keystring
blobNamestring
Returns

Promise<Blob>


putBlob

putBlob(key, blobName, blobValue): Promise<void>

desc Write a blob of a record.

Parameters
NameType
keystring
blobNamestring
blobValueBlobDesc
Returns

Promise<void>


delBlob

delBlob(key, blobName): Promise<void>

desc Delete a blob of a record.

Parameters
NameType
keystring
blobNamestring
Returns

Promise<void>

FAQs

Package last updated on 14 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc