Skip to content

Commit

Permalink
Merge pull request #31 from desci-labs/m0ar/social-handles
Browse files Browse the repository at this point in the history
Re-model social handles
  • Loading branch information
m0ar authored Dec 20, 2023
2 parents 4013fb0 + 46d2384 commit c652afc
Show file tree
Hide file tree
Showing 17 changed files with 266 additions and 87 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: clean clean-test test
.PHONY: clean clean-test test test-stop

clean:
rm -rf node_modules
Expand All @@ -15,3 +15,6 @@ test: clean-test
else \
$(MAKE) -C packages/composedb kill-test-env; false; \
fi

test-stop:
$(MAKE) -C packages/composedb kill-test-env;
78 changes: 78 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
![DeSci Codex logotype](./codex.png)

This repo contains a reference implementation for the next generation of the protocol, built on [Ceramic](https://ceramic.network/) and [ComposeDB](https://composedb.js.org/docs/0.5.x/introduction). It includes data models and an extensive test suite to ensure correct functionality, but also example data population and a GraphiQL interface to explore the protocol structure.

The repo consists of several packages:
- [the codex integration library](./packages/lib/README.md)
- [composedb models and test env](./packages/composedb/README.md)
- [a codex CLI](./packages/cli/README.md)


By default, the tests and scripts run against a local Ceramic/ComposeDB node with the bundled IPFS server, uses the `inmemory` network for anchoring, and writes all data and logs to `local-data`.

The protocol documentation can be found [here](https://codex.desci.com)!

## Getting started

1. Install dependencies:

```bash
nvm use # or otherwise ensure the use of node v20
npm ci # install deps
```

> At this point, `make test` can be run to automatically setup a local environment and run the test suite.
2. Generate your own seed, admin DID, and ComposeDB configuration file:

```bash
npm run -w packages/composedb generate
```

3. Finally, start the services:

```bash
npm run -w packages/composedb dev
```

This will start a composeDB node, compile the models into composites, and deploy the composites to a local network. Now, you can open [http://localhost:5001](http://localhost:5001) for the GraphiQL interface and explore the data models. This environment is what is being used in the tests.

> Without running this step, the composite runtime definitions will not be available and hence typescript may be temporarily sad
4. If you want to experiment with some actual queries, you can run this command to publish a bit of data from a couple of random DID's:

```bash
npm run -w packages/lib populate
```

After this is done, your GraphQL queries should return some actual data!


## Test suite

There is a test suite running through API operations demonstrating the functional protocol requirements, by generating random DID's and performing create and mutation operations. Before each run, it will remove the remains of the last test execution.

The test setup clones your user configuration, but changes storage to `local-data/ceramic-test` not to interfere with prepopulated data. It will refuse to run if `npm run dev` is already active.

```bash
make test
```

### Stop hung services
If the test doesn't exit nicely, there may be IPFS and Ceramic daemons still hanging around. When restarting the tests, it may nag about not wanting to clobber those services. If this happens, run:

```bash
make test-stop
```

## Reset

To reset to a clean state, deleting everything except generated seed and user config:

```bash
make clean
```

## Feedback

If you want to discuss any part of the protocol from a practical or theoretical perspective, come on in to our [Discord](https://discord.gg/A5P9fgB5Cf)! This is a community effort, and your thoughts and opinions will help shape its future.
Binary file added codex.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions packages/cli/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
![DeSci Codex logotype](../../codex.png)

# Codex CLI

This package is a stub for a codex CLI, demonstrating that interaction with
the protocol is possible without relying on any particular gateway. The only
thing necessary is contact with a ceramic node.
3 changes: 3 additions & 0 deletions packages/composedb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
src/__generated__/*
!src/__generates__/*.d.ts

15 changes: 15 additions & 0 deletions packages/composedb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
![DeSci Codex logotype](/codex.png)
# DeSci Codex - models and local test environment

This package contains ComposeDB models for the codex entities, together with scripts and config for setting up a local test environment and compiling composites.

## Getting started
Follow the instructions in the [repo root](/README.md) and run `make test`, and everything should be set up correctly.

### Editing models
Change models in the `composites` directory. When running `npm dev`, they will be automatically compiled and deployed.

### Adding models
Add the model file in the `composites` directory, and update [`scripts/composites.ts`](scripts/composites.ts) with the new model in the compile and deployment chain.

> The digits prefixing the file names indicate its level in the deployment DAG, as they may have dependencies on other models. So, all models starting with `1` has no dependencies. All starting with `2` have at least one dependency from the previous layer, and so on.
8 changes: 1 addition & 7 deletions packages/composedb/composites/1-profile.graphql
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
type Profile
@createModel(accountRelation: SINGLE, description: "An author profile")
@createIndex(fields: [{ path: "orcid" }])
@createIndex(fields: [{ path: "googleScholar" }])
@createIndex(fields: [{ path: "publicKey" }]) {
{
owner: DID! @documentAccount
version: CommitID! @documentVersion
displayName: String! @string(maxLength: 256)
# Should probably be generic key-value pairs, but that won't work with indexing
# for filter and sort
orcid: String @string(maxLength: 256)
googleScholar: String @string(maxLength: 256)
publicKey: String @string(maxLength: 512)
}
10 changes: 10 additions & 0 deletions packages/composedb/composites/1-socialHandle.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
type SocialHandle
@createModel(accountRelation: LIST, description: "A social handle on other platforms")
@createIndex(fields: [{ path: "platform"}])
@createIndex(fields: [{ path: "handle"}])
{
owner: DID! @documentAccount
version: CommitID! @documentVersion
platform: String! @string(maxLength: 256)
handle: String! @string(maxLength: 256)
}
2 changes: 1 addition & 1 deletion packages/composedb/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"scripts": {
"generate": "node --no-warnings=ExperimentalWarning --loader ts-node/esm scripts/generate.ts",
"dev": "node --no-warnings=ExperimentalWarning --loader ts-node/esm scripts/run.ts",
"deployComposites": "export ADMIN_SEED=$(cat admin_seed.txt) && echo \"[DEBUG] seed from deployComposites: $ADMIN_SEED \n [DEBUG] content: $(cat admin_seed.txt) \" && node --no-warnings=ExperimentalWarning --loader ts-node/esm scripts/composites.ts",
"deployComposites": "export ADMIN_SEED=$(cat admin_seed.txt) && node --no-warnings=ExperimentalWarning --loader ts-node/esm scripts/composites.ts",
"ceramic": "ceramic daemon --config composedb.config.json",
"kill": "pkill --full \"ceramic daemon|ipfs daemon\""
},
Expand Down
8 changes: 8 additions & 0 deletions packages/composedb/scripts/composites.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const ceramic = new CeramicClient("http://localhost:7007");

type Models = {
profile?: string;
socialHandle?: string;
researchObject?: string;
researchField?: string;
claim?: string;
Expand Down Expand Up @@ -44,6 +45,12 @@ export const writeComposite = async (seed: string, spinner?: Ora) => {
);
modelIDs.profile = profileComposite.modelIDs[0];

const socialHandleComposite = await createComposite(
ceramic,
"./composites/1-socialHandle.graphql",
);
modelIDs.socialHandle = socialHandleComposite.modelIDs[0];

const researchObjectComposite = await createComposite(
ceramic,
"./composites/1-researchObject.graphql",
Expand Down Expand Up @@ -154,6 +161,7 @@ export const writeComposite = async (seed: string, spinner?: Ora) => {

const composite = Composite.from([
profileComposite,
socialHandleComposite,
researchObjectComposite,
claimComposite,
attestationComposite,
Expand Down
Loading

0 comments on commit c652afc

Please sign in to comment.