Skip to content

Commit

Permalink
Merge pull request #15 from desci-labs/m0ar/metadata-and-versions
Browse files Browse the repository at this point in the history
Metadata and commitID versioning
  • Loading branch information
m0ar authored Oct 11, 2023
2 parents eead405 + b3df9b2 commit d12dc7d
Show file tree
Hide file tree
Showing 18 changed files with 509 additions and 426 deletions.
2 changes: 1 addition & 1 deletion composites/00-profile.graphql
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
type Profile
@createModel(accountRelation: SINGLE, description: "An author profile")
@createModel(accountRelation: SINGLE, description: "An author profile")
@createIndex(fields: [{ path: "orcid" }])
@createIndex(fields: [{ path: "googleScholar" }])
@createIndex(fields: [{ path: "publicKey" }])
Expand Down
1 change: 1 addition & 0 deletions composites/001-researchField.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ type ResearchField
@createModel(accountRelation: LIST, description: "A particular field of research")
{
owner: DID! @documentAccount
version: CommitID! @documentVersion
title: String! @string(maxLength: 256)
}
1 change: 1 addition & 0 deletions composites/01-researchObject.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ type ResearchObject
version: CommitID! @documentVersion
title: String! @string(maxLength: 250)
manifest: CID!
metadata: String @string(maxLength: 1024)
}
1 change: 1 addition & 0 deletions composites/02-organization.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ type Organization
@createIndex(fields: [{ path: "name" }])
{
owner: DID! @documentAccount
version: CommitID! @documentVersion
name: String! @string(maxLength: 250)
members: [DID] @list(maxLength: 100000)
}
18 changes: 11 additions & 7 deletions composites/06-attestation.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ type Claim @loadModel(id: "$CLAIM_ID") {

type Attestation
@createModel(accountRelation: LIST, description: "General attestation")
@createIndex(fields: [{ path: "targetID" }])
@createIndex(fields: [{ path: "claimID" }])
@createIndex(fields: [{ path: "revoked" }])
@createIndex(fields: [{ path: "targetID" }])
@createIndex(fields: [{ path: "targetVersion" }])
@createIndex(fields: [{ path: "claimVersion" }])
{
source: DID! @documentAccount
version: CommitID! @documentVersion
# 1. Any type of document, shown with relation on reciever end but cannot
# use @documentRelation without specifying single model
# 2. This can be CommitID if we need to lock it down, but
# we'll need to query ceramic directly for the payload
# 3. This cannot be a DID, to attestations to people target the Profile
# use @documentRelation without specifying the target type
# 2. This cannot be a DID, so attestations to people target the Profile
targetID: StreamID!
targetVersion: CommitID!

claimID: StreamID! @documentReference(model: "Claim")
claim: Claim! @relationDocument(property: "claimID")
revoked: Boolean!
claimVersion: CommitID!

# Revoke this attestation
revoked: Boolean
}
7 changes: 5 additions & 2 deletions composites/07-researchComponent.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ type ResearchObject @loadModel(id: "$RESEARCH_OBJECT_ID") {
type ResearchComponent
@createModel(
accountRelation: LIST,
description: "A contextualized DAG pointer for a research object, adding metadata to the contents"
description: "A contextualized DAG pointer for a research object"
)
@createIndex(fields: [{ path: "dagNode" }])
@createIndex(fields: [{ path: "researchObjectID" }])
@createIndex(fields: [{ path: "mimeType" }])
@createIndex(fields: [{ path: "researchObjectVersion" }])
{
owner: DID! @documentAccount
version: CommitID! @documentVersion
name: String! @string(maxLength: 512)
mimeType: String! @string(maxLength: 128)
dagNode: CID!

# The associated research object in which this component lives
researchObjectID: StreamID! @documentReference(model: "ResearchObject")
researchObject: ResearchObject! @relationDocument(property: "researchObjectID")
researchObjectVersion: CommitID!
}
9 changes: 9 additions & 0 deletions composites/08-referenceRelation.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,21 @@ type ResearchObject @loadModel(id: "$RESEARCH_OBJECT_ID") {

type ReferenceRelation
@createModel(accountRelation: LIST, description: "Indicate a reference between research objects")
@createIndex(fields: [{ path: "fromVersion" }])
@createIndex(fields: [{ path: "toVersion" }])
@createIndex(fields: [{ path: "revoked" }])
{
owner: DID! @documentAccount
version: CommitID! @documentVersion

fromID: StreamID! @documentReference(model: "ResearchObject")
from: ResearchObject! @relationDocument(property: "fromID")
fromVersion: CommitID!

toID: StreamID! @documentReference(model: "ResearchObject")
to: ResearchObject! @relationDocument(property: "toID")
toVersion: CommitID!

# Revoke this relation
revoked: Boolean
}
22 changes: 10 additions & 12 deletions composites/09-contributorRelation.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,28 @@ type Profile @loadModel(id: "$PROFILE_ID") {
type ContributorRelation
@createModel(accountRelation: LIST, description: "List a contributor on a research object")
@createIndex(fields: [{ path: "role" }])
@createIndex(fields: [{ path: "contributorID" }])
#@createIndex(fields: [{ path: ["info", "orcid"] }])
#@createIndex(fields: [{ path: ["info", "googleScholar"] }])
@createIndex(fields: [{ path: "revoked" }])
@createIndex(fields: [{ path: "researchObjectVersion" }])
{
owner: DID! @documentAccount
version: CommitID! @documentVersion

# E.g. credit taxonomy
role: String! @string(maxLength: 256)

researchObjectID: StreamID! @documentReference(model: "ResearchObject")
researchObject: ResearchObject! @relationDocument(property: "researchObjectID")
researchObjectVersion: CommitID!

# Skipping stream versioning on profile reference
contributorID: StreamID @documentReference(model: "Profile")
contributor: Profile @relationDocument(property: "contributorID")

# In case the author doesn't have a profile in the protocol, manual information
# can be listed. Otherwise, depend on what the author lists on this profile instead
info: FallbackInfo
# can be listed. Otherwise, depend on what the author lists on this profile instead.
# Arbitrary JSON mapping the service/social network to the contributors handle.
fallbackInfo: String @string(maxLength: 1024)

# Support revokation?
# Revoke this relation
revoked: Boolean
}

type FallbackInfo {
orcid: String @string(maxLength: 256)
googleScholar: String @string(maxLength: 256)
publicKey: String @string(maxLength: 512)
}
6 changes: 6 additions & 0 deletions composites/10-researchFieldRelation.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ type ResearchFieldRelation
@createModel(accountRelation: LIST, description: "Association between a research object and a field")
{
owner: DID! @documentAccount
version: CommitID! @documentVersion

researchObjectID: StreamID! @documentReference(model: "ResearchObject")
researchObject: ResearchObject! @relationDocument(property: "researchObjectID")
researchObjectVersion: CommitID!

# Skipping stream versioning on field refs
fieldID: StreamID! @documentReference(model: "ResearchField")
field: ResearchField! @relationDocument(property: "fieldID")

# Revoke this relation
revoked: Boolean
}
21 changes: 12 additions & 9 deletions composites/11-annotation.graphql
Original file line number Diff line number Diff line change
@@ -1,24 +1,27 @@
type ResearchComponent @loadModel(id: "$RESEARCH_COMPONENT_ID") {
id: ID!
}

type Claim @loadModel(id: "$CLAIM_ID") {
id: ID!
}

type Annotation
@createModel(accountRelation: LIST, description: "Research component commentary")
@createModel(accountRelation: LIST, description: "Textual commentary")
@createIndex(fields: [{ path: "targetVersion" }])
@createIndex(fields: [{ path: "claimVersion" }])
{
owner: DID! @documentAccount
version: CommitID! @documentVersion
comment: String! @string(maxLength: 1024)

componentID: StreamID! @documentReference(model: "ResearchComponent")
component: ResearchComponent! @relationDocument(property: "componentID")
targetID: StreamID! # Research object, researchComponent, or annotation as reply
targetVersion: CommitID!

# A way to identify the location of the annotation in the target component
# payload, for example a JSON path, line number, or coordinates in a pdf
# If target is a component, identify the location of the annotation
# payload. For example a JSON path, line number, or coordinates in a pdf.
path: String @string(maxLength: 512)

# Optionally tag a claim to contextualise the annotation
claimID: StreamID @documentReference(model: "Claim")
claim: Claim @relationDocument(property: "claimID")
claimVersion: CommitID!

metadataPayload: String @string(maxLength: 1024)
}
16 changes: 7 additions & 9 deletions composites/additional-relations.graphql
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
# This composite holds additional relations that cause circular dependencies when deploying
#type ResearchObjectAttestation @loadModel(id: "$RESEARCH_OBJECT_ATTESTATION_ID") {
# id: ID!
#}
#type ProfileAttestation @loadModel(id: "$PROFILE_ATTESTATION_ID") {
# id: ID!
#}
type Attestation @loadModel(id: "$ATTESTATION_ID") {
id: ID!
}
Expand All @@ -22,12 +16,13 @@ type ResearchFieldRelation @loadModel(id: "$RESEARCH_FIELD_RELATION_ID") {
}

type Annotation @loadModel(id: "$ANNOTATION_ID") {
id: ID!
replies: [Annotation] @relationFrom(model: "Annotation", property: "targetID")
replyCount: Int! @relationCountFrom(model: "Annotation", property: "targetID")
}

type ResearchComponent @loadModel(id: "$RESEARCH_COMPONENT_ID") {
annotations: [Annotation] @relationFrom(model: "Annotation", property: "componentID")
annotationCount: Int! @relationCountFrom(model: "Annotation", property: "componentID")
annotations: [Annotation] @relationFrom(model: "Annotation", property: "targetID")
annotationCount: Int! @relationCountFrom(model: "Annotation", property: "targetID")
}

type Claim @loadModel(id: "$CLAIM_ID") {
Expand All @@ -54,6 +49,9 @@ type ResearchObject @loadModel(id: "$RESEARCH_OBJECT_ID") {
contributorCount: Int! @relationCountFrom(model: "ContributorRelation", property: "researchObjectID")

researchFields: [ResearchFieldRelation] @relationFrom(model: "ResearchFieldRelation", property: "researchObjectID")

annotations: [Annotation] @relationFrom(model: "Annotation", property: "targetID")
annotationCount: Int! @relationCountFrom(model: "Annotation", property: "targetID")
}

# Support for incoming relations on CeramicAccounts is coming, but we'd need a separate
Expand Down
25 changes: 4 additions & 21 deletions scripts/composites.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { copyFileSync, readFileSync } from "fs";
import { readFileSync } from "fs";
import { CeramicClient } from "@ceramicnetwork/http-client";
import {
createComposite,
Expand Down Expand Up @@ -102,8 +102,7 @@ export const writeComposite = async (spinner) => {
const annotationSchema = readFileSync(
"./composites/11-annotation.graphql",
{ encoding: "utf-8"}
).replace("$RESEARCH_COMPONENT_ID", componentComposite.modelIDs[1])
.replace("$CLAIM_ID", researchFieldComposite.modelIDs[0]);
).replace("$CLAIM_ID", claimComposite.modelIDs[0]);

const annotationComposite = await Composite.create({
ceramic,
Expand All @@ -114,8 +113,6 @@ export const writeComposite = async (spinner) => {
"./composites/additional-relations.graphql",
{ encoding: "utf-8" }
)
// .replace("$RESEARCH_OBJECT_ATTESTATION_ID", researchAttestationComposite.modelIDs[2])
// .replace("$PROFILE_ATTESTATION_ID", profAttestationComposite.modelIDs[1])
.replace("$ATTESTATION_ID", attestationComposite.modelIDs[1])
.replace("$CLAIM_ID", claimComposite.modelIDs[0])
.replace("$RESEARCH_OBJECT_ID", researchObjComposite.modelIDs[0])
Expand All @@ -125,7 +122,7 @@ export const writeComposite = async (spinner) => {
.replace("$REFERENCE_RELATION_ID", referenceRelationComposite.modelIDs[1])
.replace("$RESEARCH_FIELD_ID", researchFieldComposite.modelIDs[0])
.replace("$RESEARCH_FIELD_RELATION_ID", researchFieldRelationComposite.modelIDs[2])
.replace("$ANNOTATION_ID", annotationComposite.modelIDs[2]);
.replace("$ANNOTATION_ID", annotationComposite.modelIDs[1]);

const additionalRelationsComposite = await Composite.create({
ceramic,
Expand Down Expand Up @@ -160,21 +157,7 @@ export const writeComposite = async (spinner) => {
"./src/__generated__/definition.json"
);

// This is rediculous but there is a combination of things forcing
// requirements on the filenames
copyFileSync(
'./src/__generated__/definition.js',
'./src/__generated__/definition.mjs'
);
const { definition } = await import('../src/__generated__/definition.mjs');
const aliases = Object.entries(definition.models)
.map(([name, model]) => [name, model.id]);
// console.log('ALIASES:', aliases)

const aliasedDeployComposite = deployComposite.setAliases(
Object.fromEntries(aliases)
);
await aliasedDeployComposite.startIndexingOn(ceramic);
await deployComposite.startIndexingOn(ceramic);
spinner.succeed("composite deployed & ready for use");
};

Expand Down
32 changes: 23 additions & 9 deletions template_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
"dc0b1125d15f276c5e6fdaf2465ae9f25d5e9984a7cb062640345c941d3ed1e0",
"researchObjects",
1,
"id"
"IDs"
],
"toPath": [
"dc0b1125d15f276c5e6fdaf2465ae9f25d5e9984a7cb062640345c941d3ed1e0",
"researchObjects",
0,
"id"
"IDs"
]
}
],
Expand All @@ -71,7 +71,7 @@
"dc0b1125d15f276c5e6fdaf2465ae9f25d5e9984a7cb062640345c941d3ed1e0",
"researchObjects",
0,
"id"
"IDs"
],
"fieldPath": [
"1a40e10dc4830864781716eab4f88c60d74d8718cc5ed9af268d338a2096833f",
Expand All @@ -84,7 +84,7 @@
"dc0b1125d15f276c5e6fdaf2465ae9f25d5e9984a7cb062640345c941d3ed1e0",
"researchObjects",
1,
"id"
"IDs"
],
"fieldPath": [
"1a40e10dc4830864781716eab4f88c60d74d8718cc5ed9af268d338a2096833f",
Expand Down Expand Up @@ -123,7 +123,7 @@
"17cd4168d7f322ef17a01dde0ae0900cf9beebdf2c2edd39029041819cdb1015",
"researchObjects",
0,
"id"
"IDs"
],
"contributorPath": [
"dc0b1125d15f276c5e6fdaf2465ae9f25d5e9984a7cb062640345c941d3ed1e0",
Expand All @@ -138,7 +138,7 @@
"17cd4168d7f322ef17a01dde0ae0900cf9beebdf2c2edd39029041819cdb1015",
"researchObjects",
0,
"id"
"IDs"
],
"fieldPath": [
"1a40e10dc4830864781716eab4f88c60d74d8718cc5ed9af268d338a2096833f",
Expand All @@ -154,7 +154,7 @@
"17cd4168d7f322ef17a01dde0ae0900cf9beebdf2c2edd39029041819cdb1015",
"researchObjects",
0,
"id"
"IDs"
],
"claimPath": [
"1a40e10dc4830864781716eab4f88c60d74d8718cc5ed9af268d338a2096833f",
Expand Down Expand Up @@ -188,7 +188,7 @@
"17cd4168d7f322ef17a01dde0ae0900cf9beebdf2c2edd39029041819cdb1015",
"researchObjects",
0,
"id"
"IDs"
],
"claimPath": [
"1a40e10dc4830864781716eab4f88c60d74d8718cc5ed9af268d338a2096833f",
Expand All @@ -201,7 +201,7 @@
{
"comment": "I viewed this dataset and it seems to check out!",
"path": ".",
"componentPath": [
"targetPath": [
"17cd4168d7f322ef17a01dde0ae0900cf9beebdf2c2edd39029041819cdb1015",
"researchObjects",
0,
Expand All @@ -213,6 +213,20 @@
"claims",
1
]
},
{
"comment": "I recommend this RO gets stamped as quality content",
"targetPath": [
"17cd4168d7f322ef17a01dde0ae0900cf9beebdf2c2edd39029041819cdb1015",
"researchObjects",
0,
"IDs"
],
"claimPath": [
"1a40e10dc4830864781716eab4f88c60d74d8718cc5ed9af268d338a2096833f",
"claims",
0
]
}
]
}
Expand Down
Loading

0 comments on commit d12dc7d

Please sign in to comment.