Skip to content

Commit

Permalink
Rename version => commitID
Browse files Browse the repository at this point in the history
  • Loading branch information
m0ar committed Oct 11, 2023
1 parent 52e5964 commit 80896b9
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export type MutationTarget =

export type NodeIDs = {
streamID: string,
version: string
commitID: string
};

export type SidebarProps = {
Expand Down
56 changes: 28 additions & 28 deletions utils/populate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import { DID } from "dids"
import { fromString } from "uint8arrays/from-string"
import untypedTemplateData from "../template_data.json"
import { ComposeClient } from "@composedb/client"
import {
mutationCreateAnnotation,
import {
mutationCreateAnnotation,
mutationCreateAttestation,
mutationCreateClaim,
mutationCreateContributorRelation,
Expand All @@ -20,8 +20,8 @@ import { CeramicClient } from "@ceramicnetwork/http-client"
import { definition } from '@/src/__generated__/definition'
import { RuntimeCompositeDefinition } from "@composedb/types"
import { Annotation, Attestation, NodeIDs, ROProps } from "@/types"
import {
AnnotationTemplate,
import {
AnnotationTemplate,
AttestationTemplate,
ContributorRelationTemplate,
DataTemplate,
Expand All @@ -46,7 +46,7 @@ const didFromSeed = async (seed: string) => {
return did;
};

type ProfileIndexResults = { data: { profileIndex: { edges: []}}}
type ProfileIndexResults = { data: { profileIndex: { edges: [] } } }
export const loadIfUninitialised = async (ceramic: CeramicClient) => {
const composeClient = new ComposeClient(
{
Expand Down Expand Up @@ -133,7 +133,7 @@ const loadTemplateData = async (composeClient: ComposeClient) => {
);

streamIndex[seed].contributorRelations = await Promise.all(
template.contributorRelations.map((contTemplate: any) =>
template.contributorRelations.map((contTemplate: any) =>
loadContributorRelation(contTemplate, streamIndex, composeClient)
)
);
Expand Down Expand Up @@ -173,21 +173,21 @@ const loadResearchObject = async (
roTemplate: ResearchObjectTemplate,
composeClient: ComposeClient
): Promise<ActorDataNodeIDs['researchObjects'][number]> => {
const roProps: ROProps = {
const roProps: ROProps = {
title: roTemplate.title,
manifest: roTemplate.manifest
}
const researchObject = await mutationCreateResearchObject(composeClient, roProps);

// Possibly create manifest components if such exist
const components = await Promise.all(
roTemplate.components.map((c: any) =>
roTemplate.components.map((c: any) =>
mutationCreateResearchComponent(
composeClient,
{
composeClient,
{
...c,
researchObjectID: researchObject.streamID,
researchObjectVersion: researchObject.version
researchObjectVersion: researchObject.commitID
}
)
)
Expand All @@ -205,12 +205,12 @@ const loadContributorRelation = async (
const researchObject = recursePathToID(streamIndex, researchObjectPath);
const contributor = recursePathToID(streamIndex, contributorPath);
return await mutationCreateContributorRelation(
composeClient,
composeClient,
{
role,
contributorID: contributor.streamID,
researchObjectID: researchObject.streamID,
researchObjectVersion: researchObject.version
role,
contributorID: contributor.streamID,
researchObjectID: researchObject.streamID,
researchObjectVersion: researchObject.commitID
}
);
};
Expand All @@ -224,12 +224,12 @@ const loadReferenceRelation = async (
const to = recursePathToID(streamIndex, toPath);
const from = recursePathToID(streamIndex, fromPath);
return await mutationCreateReferenceRelation(
composeClient,
composeClient,
{
toID: to.streamID,
toVersion: to.version,
toVersion: to.commitID,
fromID: from.streamID,
fromVersion: from.version
fromVersion: from.commitID
}
);
};
Expand All @@ -243,10 +243,10 @@ const loadResearchFieldRelation = async (
const researchObject = recursePathToID(streamIndex, researchObjectPath);
const field = recursePathToID(streamIndex, fieldPath);
return await mutationCreateResearchFieldRelation(
composeClient,
composeClient,
{
researchObjectID: researchObject.streamID,
researchObjectVersion: researchObject.version,
researchObjectVersion: researchObject.commitID,
fieldID: field.streamID
}
);
Expand All @@ -260,11 +260,11 @@ const loadAttestation = async (
const { targetPath, claimPath } = attestationTemplate;
const target = recursePathToID(streamIndex, targetPath);
const claim = recursePathToID(streamIndex, claimPath);
const attestation: Attestation = {
targetID: target.streamID,
targetVersion: target.version,
const attestation: Attestation = {
targetID: target.streamID,
targetVersion: target.commitID,
claimID: claim.streamID,
claimVersion: claim.version,
claimVersion: claim.commitID,
revoked: false
};
return mutationCreateAttestation(composeClient, attestation);
Expand All @@ -277,15 +277,15 @@ const loadAnnotation = async (
): Promise<ActorDataNodeIDs['annotations'][number]> => {
const { comment, path, targetPath, claimPath } = annotationTemplate;
const target = recursePathToID(streamIndex, targetPath);
const annotation: Annotation = {
const annotation: Annotation = {
targetID: target.streamID,
targetVersion: target.version,
targetVersion: target.commitID,
comment
};
if (claimPath) {
const claim = recursePathToID(streamIndex, claimPath);
annotation.claimID = claim.streamID;
annotation.claimVersion = claim.version;
annotation.claimVersion = claim.commitID;
};
if (path) {
annotation.path = path;
Expand Down
40 changes: 20 additions & 20 deletions utils/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { ExecutionResult } from "graphql";
export const queryViewerId = async (
composeClient: ComposeClient
): Promise<string> => {
const response = await composeClient.executeQuery<{viewer: { id: string}}>(`
const response = await composeClient.executeQuery<{ viewer: { id: string } }>(`
query {
viewer {
id
Expand All @@ -22,7 +22,7 @@ export const queryViewerId = async (
export const queryViewerProfile = async (
composeClient: ComposeClient
): Promise<Profile | null> => {
const response = await composeClient.executeQuery<{ viewer: { profile: Profile | null} }>(`
const response = await composeClient.executeQuery<{ viewer: { profile: Profile | null } }>(`
query {
viewer {
profile {
Expand Down Expand Up @@ -65,7 +65,7 @@ export const queryViewerClaims = async (
composeClient: ComposeClient
): Promise<Claim[]> => {
const response = await composeClient.executeQuery<
{ viewer:{ claimList: { edges: { node: Claim}[] } } }
{ viewer: { claimList: { edges: { node: Claim }[] } } }
>(`
query {
viewer {
Expand Down Expand Up @@ -218,7 +218,7 @@ export const mutationCreateClaim = async (
);

export const mutationCreateAttestation = async (
composeClient: ComposeClient,
composeClient: ComposeClient,
inputs: Attestation
): Promise<NodeIDs> => genericCreate(
composeClient,
Expand All @@ -234,7 +234,7 @@ export const mutationCreateAttestation = async (
);

export const mutationUpdateAttestation = async (
composeClient: ComposeClient,
composeClient: ComposeClient,
inputs: Partial<Attestation> & { id: string }
): Promise<NodeIDs> => genericUpdate(
composeClient,
Expand All @@ -248,7 +248,7 @@ export const mutationUpdateAttestation = async (
);

export const mutationCreateAnnotation = async (
composeClient: ComposeClient,
composeClient: ComposeClient,
inputs: Annotation
): Promise<NodeIDs> => genericCreate(
composeClient,
Expand Down Expand Up @@ -344,9 +344,9 @@ async function genericCreate<T extends MutationTarget>(
}`, inputs
) as any;
assertMutationErrors(response, mutationName);
const nodeIDs = {
const nodeIDs: NodeIDs = {
streamID: response.data[mutationName].document.id,
version: response.data[mutationName].document.version
commitID: response.data[mutationName].document.version
};
return nodeIDs;
};
Expand Down Expand Up @@ -376,9 +376,9 @@ async function genericUpdate<T extends MutationTarget>(
}`, inputs
) as any;
assertMutationErrors(response, mutationName);
const nodeIDs = {
const nodeIDs: NodeIDs = {
streamID: response.data[mutationName].document.id,
version: response.data[mutationName].document.version
commitID: response.data[mutationName].document.version
};
return nodeIDs;
}
Expand All @@ -401,8 +401,8 @@ const assertQueryErrors = (
queryDescription: string
) => {
if (result.errors || !result.data) {
console.error("Error:", result.errors?.toString());
throw new Error(`Query failed: ${queryDescription}!`);
console.error("Error:", result.errors?.toString());
throw new Error(`Query failed: ${queryDescription}!`);
};
}

Expand All @@ -423,11 +423,11 @@ const getQueryFields = (
inputs: Record<string, unknown>
) =>
Object.keys(inputs)
.filter(p => p !== 'id')
.reduce<[string[], string[]]>(
(acc, next) => [
[...acc[0], `$${next}: ${graphQLParamTypes[next]}`],
[...acc[1], `${next}: $${next}`]
],
[[],[]]
).map(stringArr => stringArr.join(', '));
.filter(p => p !== 'id')
.reduce<[string[], string[]]>(
(acc, next) => [
[...acc[0], `$${next}: ${graphQLParamTypes[next]}`],
[...acc[1], `${next}: $${next}`]
],
[[], []]
).map(stringArr => stringArr.join(', '));

0 comments on commit 80896b9

Please sign in to comment.