-
Notifications
You must be signed in to change notification settings - Fork 2
/
bootstrap.js
107 lines (98 loc) · 2.64 KB
/
bootstrap.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const { writeFile } = require('fs').promises
const Ceramic = require('@ceramicnetwork/http-client').default
const { createDefinition, publishSchema } = require('@ceramicstudio/idx-tools')
const { Ed25519Provider } = require('key-did-provider-ed25519')
const fromString = require('uint8arrays/from-string')
const CERAMIC_URL = 'https://ceramic-clay.3boxlabs.com'
const TaskSchema = {
$schema: 'http://json-schema.org/draft-07/schema#',
title: 'Task',
type: 'object',
properties: {
date: {
type: 'string',
format: 'date-time',
title: 'date',
maxLength: 30,
},
title: {
type: 'string',
title: 'title',
maxLength: 4000,
},
text: {
type: 'string',
title: 'text',
maxLength: 4000,
},
completed: {
type: 'boolean',
title: 'completed',
},
},
}
const TasksListSchema = {
$schema: 'http://json-schema.org/draft-07/schema#',
title: 'TasksList',
type: 'object',
properties: {
tasks: {
type: 'array',
title: 'tasks',
items: {
type: 'object',
title: 'TaskItem',
properties: {
id: {
$ref: '#/definitions/CeramicDocId',
},
title: {
type: 'string',
title: 'title',
maxLength: 100,
},
},
},
},
},
definitions: {
CeramicDocId: {
type: 'string',
pattern: '^ceramic://.+(\\\\?version=.+)?',
maxLength: 150,
},
},
}
async function run() {
// The seed must be provided as an environment variable
const seed = fromString(process.env.SEED, 'base16')
// Connect to the local Ceramic node
const ceramic = new Ceramic(CERAMIC_URL)
// Authenticate the Ceramic instance with the provider
await ceramic.setDIDProvider(new Ed25519Provider(seed))
// Publish the two schemas
const [taskSchema, tasksListSchema] = await Promise.all([
publishSchema(ceramic, { content: TaskSchema }),
publishSchema(ceramic, { content: TasksListSchema }),
])
// Create the definition using the created schema ID
const tasksDefinition = await createDefinition(ceramic, {
name: 'tasks',
description: 'Simple text tasks',
schema: tasksListSchema.commitId.toUrl(),
})
// Write config to JSON file
const config = {
definitions: {
tasks: tasksDefinition.id.toString(),
},
schemas: {
Task: taskSchema.commitId.toUrl(),
TasksList: tasksListSchema.commitId.toUrl(),
},
}
await writeFile('./src/config.json', JSON.stringify(config))
console.log('Config written to src/config.json file:', config)
process.exit(0)
}
run().catch(console.error)