spctcl / metasign

0 stars 0 forks source link

have a function somewhere that makes and publishes a model #8

Open bshambaugh opened 2 years ago

bshambaugh commented 2 years ago

Here is a sketch --- remove stuff declared elsewhere from the function::

import { CeramicClient } from '@ceramicnetwork/http-client' import { ModelManager } from '@glazed/devtools'

const schemaString = userSchema.commitId.toString(); /// from within createDeviceSchema

function writeModel(schemaString) { const ceramic = new CeramicClient() const manager = new ModelManager(ceramic) await manager.usePublishedSchema('MySchema', 'ceramic://'+schemaString) // http://localhost:7007/api/v0/streams/k3y52l7qbv1frxvx5tmayzf3wft9v5pgti9ql1ex5mjbzfglxgjxgtbaexpkh1fr4 const encodedModel = await manager.toJSON() / / The clonedManager instance will contain the same model as the manager instance const clonedManager = ModelManager.fromJSON(ceramic, encodedModel)

// The published model could then itself be exported to be used at runtime const publishedModel = await clonedManager.toPublished() await writeFile(new URL('published-model.json', import.meta.url), JSON.stringify(publishedModel)) }

bshambaugh commented 2 years ago

function writeModel(ceramic,schemaString) { const manager = new ModelManager(ceramic) await manager.usePublishedSchema('MySchema', 'ceramic://'+schemaString) // http://localhost:7007/api/v0/streams/k3y52l7qbv1frxvx5tmayzf3wft9v5pgti9ql1ex5mjbzfglxgjxgtbaexpkh1fr4 const encodedModel = await manager.toJSON() / / The clonedManager instance will contain the same model as the manager instance const clonedManager = ModelManager.fromJSON(ceramic, encodedModel)

// The published model could then itself be exported to be used at runtime const publishedModel = await clonedManager.toPublished() await writeFile(new URL('published-model.json', import.meta.url), JSON.stringify(publishedModel)) }