-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateModel.js
76 lines (70 loc) · 1.82 KB
/
createModel.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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();