iframe-ai

0.0.14 • Public • Published

iFrameAI SDK

Introduction

The iFrameAI SDK is an open-source SDK that allows developers to build awesome apps with iFrameDB, a graph database. This documentation provides an overview of the SDK and its features, as well as code examples to help you get started.

iFrameAI Community is an open-source project providing complete infrastructure for building enterprise-level apps: including angular-based UX/UI interface for zero-code apps builder; JS SDK to automate dataflow; AI connectors to work with your favorite LLM, AutoML, GPT and other models. Ready to go back-end, and free access to iFrameAI Graph Database.

Find more information on our website: www.iframe.ai

Installation

To install the iFrameAI SDK, you will need to have Node.js installed on your machine. Once you have Node.js installed, you can install the SDK using npm, the Node.js package manager. Run the following command in your terminal:

npm install iframe-ai

Usage

To use the iFrameAI SDK in your application, you will first need to import the necessary modules. Here is an example:

const { iFrameDbClient, BaseVertexModel, BaseEdgeModel } = require('iframe-ai');

Initialization

Before you can start using the SDK, you will need to initialize a iFrameDbClient object. The iFrameDbClient is responsible for establishing a connection to the iFrameDB server. Here is an example of how to initialize a iFrameDbClient:

const dbClient = new iFrameDbClient('your_secret_key');

Connecting to iFrameDB

After initializing the iFrameDbClient, you can connect to the iFrameDB server using the connect() method. This method establishes a WebSocket connection to the server. Here is an example:

await dbClient.connect();

Vertex Models

Vertex models represent vertices in the iFrameDB graph. You can create your own vertex models by extending the BaseVertexModel class.

Here is an example of a custom vertex model:

class User extends BaseVertexModel {
  constructor(client, properties) {
    super(client, 'User', properties);
  }
}

const user = new User(dbClient, { name: 'John Doe' });

Edge Models

Edge models represent edges in the iFrameDB graph. You can create your own edge models by extending the BaseEdgeModel class.

Here is an example of a custom edge model:

class Follows extends BaseEdgeModel {
  constructor(client, fromId, toId) {
    super(client);
    this.fromId = fromId;
    this.toId = toId;
  }
}

const follows = new Follows(dbClient, 'user1', 'user2');

Transactions

Transactions allow you to perform multiple operations as a single atomic unit. You can use the Transaction class to define and commit transactions.

Here is an example of how to use transactions:

const transaction = new Transaction();

// Add a vertex
transaction.addVertex('User', { name: 'John Doe' });

// Add an edge
transaction.addEdge('user1', 'user2', 'Follows', {});

// Commit the transaction
await transaction.commit(dbClient);

Querying the Graph

The SDK provides a query builder that allows you to construct complex queries using a fluent interface.

Here is an example of how to use the query builder:

const query = new QueryBuilder(dbClient.getTraversal());

query.select('name', 'age')
  .where('name', 'John')
  .orderBy('age', 'desc')
  .limit(10)
  .offset(0);

const results = await query.getQuery().toList();

Closing the Connection

After you are done using the SDK, it is important to close the connection to the iFrameDB server. You can close the connection by calling the closeConnection() method on the iFrameDbClient object.

Here is an example of how to close the connection:

await dbClient.closeConnection();

iFrameAI Graph Database Client

The iFrameDbClient class is responsible for establishing a connection to the iFrameDB server. It provides methods for connecting to the server, retrieving the traversal object, and closing the connection.

Example:

const dbClient = new iFrameDbClient(secretKey, options);
await dbClient.connect();
const traversal = await dbClient.getTraversal();
await dbClient.closeConnection();

BaseVertexModel

The BaseVertexModel class is a base class for creating vertex models in iFrameDB. It provides methods for saving, deleting, and loading vertices, as well as managing their properties.

Example:

class User extends BaseVertexModel {
  constructor(client, properties) {
    super(client, 'User', properties);
  }
}

const user = new User(dbClient, { name: 'John Doe' });
await user.save();
await user.delete();
await user.load('id');

BaseEdgeModel

The BaseEdgeModel class is a base class for creating edge models in iFrameDB. It provides methods for saving, deleting, and loading edges, as well as managing their properties.

Example:

class Follows extends BaseEdgeModel {
  constructor(client, fromId, toId) {
    super(client);
    this.fromId = fromId;
    this.toId = toId;
  }
}

const follows = new Follows(dbClient, 'user1', 'user2');
await follows.save();
await follows.delete();
await follows.load();

Transaction

The Transaction class allows you to perform multiple operations as a single atomic unit. It provides methods for adding vertices and edges, as well as committing or rolling back the transaction.

Example:

const transaction = new Transaction();
transaction.addVertex('User', { name: 'John Doe' });
transaction.addEdge('user1', 'user2', 'Follows', {});
await transaction.commit(dbClient);
transaction.rollback();

SchemaManager

The SchemaManager class provides methods for creating and altering vertex and edge schemas in iFrameDB. It allows you to define the properties of vertices and edges.

Example:

const schemaManager = new SchemaManager(dbClient);
await schemaManager.createVertexSchema('User', [
  ['name', 'string'],
  ['age', 'number'],
]);
await schemaManager.createEdgeSchema('Follows', [
  ['date', 'date'],
]);

HookManager

The HookManager class allows you to register and execute hooks in iFrameDB. Hooks are functions that are triggered by certain events, such as saving or deleting a vertex.

Example:

const hookManager = new HookManager();
hookManager.registerHook('beforeSave', (vertex) => {
  // Do something before saving the vertex
});
await hookManager.executeHook('beforeSave', vertex);

QueryBuilder

The QueryBuilder class provides a fluent interface for building complex queries in iFrameDB. It allows you to select properties, apply filters, order and limit the results.

Example:

const queryBuilder = new QueryBuilder(dbClient.getTraversal());
const query = queryBuilder
  .select('name', 'age')
  .where('age', 18)
  .orderBy('name')
  .limit(10)
  .offset(0)
  .getQuery();
const results = await query.toList();

iFrameDbAdapter

The iFrameDbAdapter class provides an adapter for interacting with iFrameDB using a different database connection or driver. It allows you to create a session, execute queries, and terminate the session.

Example:

const adapter = new iFrameDbAdapter(config, logger);
await adapter.createSession();
const result = await adapter.executeQuery('SELECT * FROM User');
await adapter.terminateSession();

NativeIFrameDB

The NativeIFrameDB class provides a wrapper for executing raw queries in iFrameDB. It allows you to execute queries directly without using the query builder.

Example:

const nativeDb = new NativeIFrameDB(dbClient);
const result = await nativeDb.execute('SELECT * FROM User');

TypeResolver

The TypeResolver class provides methods for resolving different types of values in iFrameDB. It allows you to perform type-based queries on the graph.

Example:

const resolver = new TypeResolver(dbClient.getTraversal());
const result = await resolver.resolveType('string', 'name', 'John');

TraversalBuilder

The TraversalBuilder class provides a fluent interface for building traversals in iFrameDB. It allows you to chain traversal steps and apply filters.

Example:

const traversalBuilder = new TraversalBuilder(dbClient.getTraversal());
const traversal = traversalBuilder
  .inE('Follows')
  .outV()
  .has('age', 18)
  .getQuery();
const result = await traversal.toList();

DynamicLoader

The DynamicLoader class provides methods for dynamically loading entities in iFrameDB. It allows you to load entities by their label and ID.

Example:

const loader = new DynamicLoader(dbClient);
const entity = await loader.load('User', 'userId');

QueryDSL

The QueryDSL class provides a way to construct complex queries using a DSL-like syntax. It allows you to chain traversal steps and apply filters in a readable manner.

Example:

const queryDSL = new QueryDSL(dbClient.getTraversal());
const result = await queryDSL
  .V('userId')
  .hasLabel('User')
  .values('name')
  .toList();

VertexManager

The VertexManager class provides methods for adding and retrieving properties and annotations of vertices in iFrameDB. It allows you to manage the properties and annotations of vertices.

Example:

const vertexManager = new VertexManager(dbClient);
await vertexManager.addProperty('userId', 'age', 25);
const age = await vertexManager.getProperty('userId', 'age');

EdgeManager

The EdgeManager class provides methods for adding and removing edges in iFrameDB. It allows you to manage the relationships between vertices.

Example:

const edgeManager = new EdgeManager(dbClient);
await edgeManager.addEdge('user1', 'user2', 'Follows');
await edgeManager.removeEdge('user1', 'user2', 'Follows');

Annotator

The Annotator class provides methods for annotating vertices in iFrameDB. It allows you to create annotations between vertices.

Example:

const annotator = new Annotator(dbClient.getTraversal());
await annotator.annotate('user1', 'Follows', 'user2');

iFrameDB

The iFrameDB class provides an interface for interacting with iFrameDB database. It provides methods for performing CRUD operations and managing the database.

Example:

const db = new iFrameDB();
await db.create('User', { name: 'John Doe' });
const user = await db.get('User', 'userId');
await db.update('User', 'userId', { name: 'Jane Smith' });
await db.delete('User', 'userId');

iFrameUser

The iFrameUser class represents a user vertex in iFrameDB. It provides methods for managing user-related operations and relationships.

Example:

const user = new iFrameUser(dbClient, { name: 'John Doe' });
await user.save();
await user.follow('user2');
const followers = await user.getFollowers();

iFrameAccount

The iFrameAccount class represents an account vertex in iFrameDB. It provides methods for managing account-related operations and relationships.

Example:

const account = new iFrameAccount(dbClient, { name: 'Account 1' });
await account.save();
await account.createProject('Project 1');
const projects = await account.getProjects();

IFrameApp

The IFrameApp class represents a project vertex in iFrameDB. It provides methods for managing project-related operations and relationships.

Example:

const project = new IFrameApp(dbClient, {name: 'Project 1'});
await project.save();
await project.addUnit('Unit 1');
const units = await project.getUnits();

iFrameUnit

The iFrameUnit class represents a unit vertex in iFrameDB. It provides methods for managing unit-related operations and relationships.

Example:

const unit = new iFrameUnit(dbClient, { name: 'Unit 1' });
await unit.save();
await unit.addDataset('Dataset 1');
const datasets = await unit.getDatasets();

iFrameView

The iFrameView class represents a view vertex in iFrameDB. It provides methods for managing view-related operations and relationships.

Example:

const view = new iFrameView(dbClient, { name: 'View 1' });
await view.save();
await view.addFeature('Feature 1');
const features = await view.getFeatures();

iFrameFeature

The iFrameFeature class represents a feature vertex in iFrameDB. It provides methods for managing feature-related operations and relationships.

Example:

const feature = new iFrameFeature(dbClient, { name: 'Feature 1' });
await feature.save();
await feature.addOption('Option 1');
const options = await feature.getOptions();

iFrameOption

The iFrameOption class represents an option vertex in iFrameDB. It provides methods for managing option-related operations and relationships.

Example:

const option = new iFrameOption(dbClient, { name: 'Option 1' });
await option.save();
const features = await option.getFeatures();

iFrameDataset

The iFrameDataset class represents a dataset vertex in iFrameDB. It provides methods for managing dataset-related operations and relationships.

Example:

const dataset = new iFrameDataset(dbClient, { name: 'Dataset 1' });
await dataset.save();
await dataset.addRecord('Record 1');
const records = await dataset.getRecords();

iFrameRecord

The iFrameRecord class represents a record vertex in iFrameDB. It provides methods for managing record-related operations and relationships.

Example:

const record = new iFrameRecord(dbClient, { name: 'Record 1' });
await record.save();
await record.addFeature('Feature 1');
const features = await record.getFeatures();

iFrameToken

The iFrameToken class represents a token vertex in iFrameDB. It provides methods for managing token-related operations and relationships.

Example:

const token = new iFrameToken(dbClient, { name: 'Token 1' });
await token.save();
await token.associateWithProject('Project 1');
const projects = await token.getAssociatedProjects();

iFrameFile

The iFrameFile class represents a file vertex in iFrameDB. It provides methods for managing file-related operations and relationships.

Example:

const file = new iFrameFile(dbClient, { name: 'File 1' });
await file.save();
await file.uploadToRecord('Record 1');
const records = await file.getUploadedRecords();

iFrameAutomation

The iFrameAutomation class represents an automation vertex in iFrameDB. It provides methods for managing automation-related operations and relationships.

Example:

const automation = new iFrameAutomation(dbClient, { name: 'Automation 1' });
await automation.save();
await automation.run();

iFrameAutoML

The iFrameAutoML class represents an AutoML vertex in iFrameDB. It provides methods for managing AutoML-related operations and relationships.

Example:

const autoML = new iFrameAutoML(dbClient, { name: 'AutoML 1' });
await autoML.save();
await autoML.train();
const logs = await autoML.getTrainingLogs();

iFrameIntegration

The iFrameIntegration class represents an integration vertex in iFrameDB. It provides methods for managing integration-related operations and relationships.

Example:

const integration = new iFrameIntegration(dbClient, { name: 'Integration 1' });
await integration.save();
await integration.updateCredentials('username', 'password');
const credentials = await integration.getCredentials();

iFrameImport

The iFrameImport class represents an import vertex in iFrameDB. It provides methods for managing import-related operations and relationships.

Example:

const importJob = new iFrameImport(dbClient, { name: 'Import 1' });
await importJob.save();
await importJob.importToDataset('Dataset 1');
const datasets = await importJob.getImportedDatasets();

Package Sidebar

Install

npm i iframe-ai

Weekly Downloads

2

Version

0.0.14

License

Apache-2.0

Unpacked Size

116 kB

Total Files

46

Last publish

Collaborators

  • iframe_ai