Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mzkrasner committed Oct 2, 2024
0 parents commit 4835f76
Show file tree
Hide file tree
Showing 7 changed files with 5,722 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "next/core-web-vitals"
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# dependencies
/node_modules
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Simple OrbisDB Model Deployment Boilerplate

You can use this repository to help deploy data models of any complexity to the Ceramic Network (to use with OrbisDB) that you cannot achieve through the [Orbis Studio](https://studio.useorbis.com/).

## Getting Started

1. Install your dependencies

```bash
npm install
```

2. Replace the `def` object in [createModel.js](createModel.js) with your own

3. Replace `env` on line 58 in [createModel.js](createModel.js) with your own

4. When ready, run the following command to deploy your data model:

```bash
npm run create-model
```
76 changes: 76 additions & 0 deletions createModel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
import { OrbisDB } from "@useorbis/db-sdk";
import { OrbisKeyDidAuth } from "@useorbis/db-sdk/auth";

const deploy = async () => {
// replace this with your model definition
const def = {
version: "2.0",
name: "pageview",
views: {
issuer: {
type: "documentAccount",
},
},
schema: {
type: "object",
$defs: {
DateTime: {
type: "string",
title: "DateTime",
format: "date-time",
maxLength: 100,
},
},
$schema: "https://json-schema.org/draft/2020-12/schema",
required: ["page", "address", "timestamp", "customer_user_id"],
properties: {
page: {
type: "string",
},
address: {
type: "string",
},
timestamp: {
$ref: "#/$defs/DateTime",
},
customer_user_id: {
type: "integer",
},
},
additionalProperties: false,
},
interface: false,
implements: [],
accountRelation: {
type: "list",
},
immutableFields: [],
};

// create a new OrbisDB instance
const orbis = new OrbisDB({
ceramic: {
gateway: "https://ceramic-orbisdb-mainnet-direct.hirenodes.io/",
},
nodes: [
{
gateway: "https://studio.useorbis.com",
env: "<your env ID here>",
},
],
});

// generate a seed or use an existing one
const seed = await OrbisKeyDidAuth.generateSeed("hex");

// authenticate with the seed
const auth = await OrbisKeyDidAuth.fromSeed(seed);
await orbis.connectUser({ auth });

// deploy the model
//@ts-ignore
const deployed = await orbis.ceramic.createModel(def);
console.log(deployed); // this will log your table's ID --> you can view this in your browser by visiting https://cerscan.com/mainnet/stream/<your table ID>
};

deploy();
Loading

0 comments on commit 4835f76

Please sign in to comment.