UNPKG

@chevre/domain

Version:

Chevre Domain Library for Node.js

72 lines (61 loc) 2.17 kB
// tslint:disable:no-console import * as mongoose from 'mongoose'; import { chevre } from '../../../lib/index'; const project = { id: String(process.env.PROJECT_ID) }; const IDENTIFIER = 'sampleidentity20250528'; async function main() { await mongoose.connect(<string>process.env.MONGOLAB_URI, { autoIndex: false }); const identityRepo = await chevre.repository.Identity.createInstance(mongoose.connection); let docs = await identityRepo.projectIdentityFields( { project: { id: { $eq: project.id } }, about: { id: { $eq: IDENTIFIER } } }, ['about', 'typeOf', 'issuedBy', 'project'] ); console.log('docs:', docs); console.log(docs.length, 'docs found'); if (docs.length > 0) { await identityRepo.deleteIdentityById({ project: { id: docs[0].project.id }, id: docs[0].id }); console.log('deleted', docs[0].id); } await identityRepo.projectIdentityFields( { project: { id: { $eq: project.id } }, about: { id: { $eq: IDENTIFIER } } }, ['about', 'typeOf', 'issuedBy', 'project'] ); console.log('docs:', docs); console.log(docs.length, 'docs found'); await identityRepo.saveIdentity({ attributes: { project: { id: project.id, typeOf: chevre.factory.organizationType.Project }, typeOf: chevre.factory.creativeWorkType.Certification, about: { id: IDENTIFIER, typeOf: chevre.factory.creativeWorkType.WebApplication }, issuedBy: [{ identifier: 'https://example.com', typeOf: chevre.factory.organizationType.Organization }] } }); console.log('created.'); docs = await await identityRepo.projectIdentityFields( { project: { id: { $eq: project.id } }, about: { id: { $eq: IDENTIFIER } } }, ['about', 'typeOf', 'issuedBy', 'project'] ); console.log('docs:', docs); console.log(docs.length, 'docs found'); } main() .then() .catch(console.error);