Skip to content

Commit

Permalink
feat: add deleteAfter support, move earthstar to peerdeps
Browse files Browse the repository at this point in the history
  • Loading branch information
sgwilym committed Aug 20, 2020
1 parent 8774438 commit 55d0255
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 26 deletions.
10 changes: 8 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,19 @@

### Breaking

- The `format` arg on the `syncWithPub` mutation has been removed as whether a pub is a GraphQL or REST pub is now automatically determined.
- The `format` arg on the `syncWithPub` mutation has been removed, as whether a pub is a GraphQL or REST pub is now automatically determined.

### Features

- Added a `isGraphQlPub` export which can be used to determine whether the pub at a URL is a GraphQL pub or not.
- Added a `isGraphQlPub` function export which can be used to determine whether the pub at a URL is a GraphQL pub or not.
- Added a optional `deletedAfter` arg to the `set` mutation so that ephemeral documents can be created
- If the workspace passed to a `syncWithPub` mutation does not exist, `syncWithPub` will create it if it passes the configurable `canAddWorkspace` check.

### Internal

- earthstar dependency updated to 5.2.3
- earthstar moved into peer dependencies, as clients which may also depend on the earthstar package should use the same version.

## 4.2.0

### Improvements
Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "earthstar-graphql",
"license": "AGPL-3.0",
"version": "4.2.0",
"version": "5.0.0",
"dependencies": {
"cross-fetch": "^3.0.5",
"earthstar": "^5.0.0",
"graphql-type-json": "0.3.2",
"js-base64": "3.2.4"
},
"peerDependencies": {
"earthstar": "5.2.3",
"graphql": "^15.3.0"
},
"main": "dist/index.js",
Expand All @@ -28,6 +28,7 @@
"validate": "yarn run ts-graphql-plugin validate --exitOnWarn"
},
"devDependencies": {
"earthstar": "5.2.3",
"@babel/preset-env": "^7.10.4",
"@babel/preset-typescript": "^7.10.4",
"@types/jest": "^26.0.5",
Expand Down
20 changes: 17 additions & 3 deletions src/query.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import createSchemaContext from "./create-schema-context";
import { generateAuthorKeypair, sign, verify, AuthorKeypair } from "earthstar";
import { DeletedDocumentsQuery } from "./__generated__/deleted-documents-query";
import { LongNameQuery } from "./__generated__/long-name-query";
import { TestMutation } from "./__generated__/test-mutation";

export const TEST_WORKSPACE_ADDR = "+test.a123";

Expand Down Expand Up @@ -35,9 +36,15 @@ describe("query", () => {
workspaceAddresses: [TEST_WORKSPACE_ADDR],
});

const DELETE_AFTER = Date.now() * 1000 + 10000000;

const variables = {
author: generateAuthorKeypair("test"),
document: { path: "/testing", content: "is fun!" },
document: {
path: "/!testing",
content: "is fun!",
deleteAfter: DELETE_AFTER,
},
workspace: TEST_WORKSPACE_ADDR,
};

Expand All @@ -48,20 +55,27 @@ describe("query", () => {
$workspace: String!
) {
set(author: $author, document: $document, workspace: $workspace) {
__typename
... on DocumentRejectedError {
errorName
reason
}
... on SetDataSuccessResult {
document {
... on ES4Document {
content
path
deleteAfter
}
}
}
}
}
`;

await query(TEST_MUTATION, variables, ctx);
await query<TestMutation>(TEST_MUTATION, variables, ctx);

expect(ctx.workspaces[0].getDocument("/testing")?.content).toEqual(
expect(ctx.workspaces[0].getDocument("/!testing")?.content).toEqual(
"is fun!"
);
});
Expand Down
8 changes: 2 additions & 6 deletions src/sync-graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,8 @@ export default async function syncGraphql(
}

const pulledDocuments: Document[] = pullJson.data.workspace.documents.map(
({ author, workspace, deleteAfter, ...rest }) => ({
({ author, workspace, ...rest }) => ({
...rest,
...(deleteAfter ? { deleteAfter } : {}),
author: author.address,
workspace: workspace.address,
})
Expand Down Expand Up @@ -212,9 +211,6 @@ export default async function syncGraphql(
document: {
...doc.document,
author: doc.document.author.address,
deleteAfter: doc.document.deleteAfter
? doc.document.deleteAfter
: undefined,
workspace: doc.document.workspace.address,
},
result:
Expand All @@ -238,7 +234,7 @@ export async function isGraphQlPub(pubUrl: string): Promise<boolean> {
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
query: /* GraphQL */ `
{
query isGqlQuery {
__schema {
queryType {
name
Expand Down
13 changes: 12 additions & 1 deletion src/types/inputs/newDocumentInput.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { GraphQLInputObjectType, GraphQLNonNull, GraphQLString } from "graphql";
import {
GraphQLInputObjectType,
GraphQLNonNull,
GraphQLString,
GraphQLFloat,
} from "graphql";
import { documentFormatEnum } from "../object-types/document";

export default new GraphQLInputObjectType({
Expand All @@ -17,5 +22,11 @@ export default new GraphQLInputObjectType({
type: GraphQLNonNull(GraphQLString),
description: "The path of the document, e.g. /spices/pepper",
},
deleteAfter: {
type: GraphQLFloat,
description:
"A timestamp representing the time this document should be deleted by",
defaultValue: null,
},
},
});
1 change: 1 addition & 0 deletions src/types/mutations/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export const setField: GraphQLFieldConfig<{}, Context> = {
format: args.document.format || "es.4",
content: args.document.content,
path: args.document.path,
deleteAfter: args.document.deleteAfter,
});

if (isErr(setResult)) {
Expand Down
24 changes: 12 additions & 12 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3344,10 +3344,10 @@ dynamic-dedupe@^0.3.0:
dependencies:
xtend "^4.0.0"

earthstar@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/earthstar/-/earthstar-5.0.0.tgz#67f0eba96517dc43bc460b8388226e6750cd98a8"
integrity sha512-ro8+AxhyIhw8lKDsupPB0SpNvDadUtLrOaPycqNoU+sWUsWL2CiWB+xCtt5KkW01PvlAhgCDxCD4byrBZs2FnQ==
earthstar@5.2.3:
version "5.2.3"
resolved "https://registry.yarnpkg.com/earthstar/-/earthstar-5.2.3.tgz#29202f5b1e5b833c054ac889a6ea9ec65189e93a"
integrity sha512-V9y1NLlbiMCshpXBwPJqjwWLvn2f5h9P2nfQxU6zjL4DtQ3549LNzi2EM+gw/X07ex4pj0D6ARzI6KT79mx0sA==
dependencies:
"@types/isomorphic-fetch" "0.0.35"
bencode "^2.0.1"
Expand Down Expand Up @@ -6340,9 +6340,9 @@ ms@^2.1.1:
integrity sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==

msw@^0.20.1:
version "0.20.1"
resolved "https://registry.yarnpkg.com/msw/-/msw-0.20.1.tgz#34804ab934905b54a2c5189d360c44faf6801945"
integrity sha512-mrQb4LFmZ6KrADb1Hl2T4yQhxwCkhDz/HRRRLl+RgguUBJ+8aqDtXxGo23Eagw+Q4zrWIyJ//fENv4H6GBeTig==
version "0.20.5"
resolved "https://registry.yarnpkg.com/msw/-/msw-0.20.5.tgz#b6141080c0d8b17c451d9ca36c28cc47b4ac487a"
integrity sha512-hmEsey5BbVicMGt7aOh/GZ9ltga5N3tK6NiJXnbfCkAGKgnAVnjASr3i7Z+sWlZyY5uuMUFyLCEcqrlXxC6qIA==
dependencies:
"@open-draft/until" "^1.0.3"
"@types/cookie" "^0.4.0"
Expand All @@ -6352,7 +6352,7 @@ msw@^0.20.1:
headers-utils "^1.2.0"
node-fetch "^2.6.0"
node-match-path "^0.4.4"
node-request-interceptor "^0.3.3"
node-request-interceptor "^0.3.5"
statuses "^2.0.0"
yargs "^15.4.1"

Expand Down Expand Up @@ -6486,10 +6486,10 @@ node-releases@^1.1.58:
resolved "https://registry.yarnpkg.com/node-releases/-/node-releases-1.1.60.tgz#6948bdfce8286f0b5d0e5a88e8384e954dfe7084"
integrity sha512-gsO4vjEdQaTusZAEebUWp2a5d7dF5DYoIpDG7WySnk7BuZDW+GPpHXoXXuYawRBr/9t5q54tirPz79kFIWg4dA==

node-request-interceptor@^0.3.3:
version "0.3.3"
resolved "https://registry.yarnpkg.com/node-request-interceptor/-/node-request-interceptor-0.3.3.tgz#4227763d1d8d696fc15f7d6e1fe0ed1dd8c9d86d"
integrity sha512-NLFD4F7sB72WSVI7YYQzaRa7PkhdbXL1cPNvu2LlGkmnLbE11EEKrRmie5gDOKy3xfk22xXPk654CbiFwaBLdA==
node-request-interceptor@^0.3.5:
version "0.3.6"
resolved "https://registry.yarnpkg.com/node-request-interceptor/-/node-request-interceptor-0.3.6.tgz#c411065a424b17a17503ecfce11a6a2a2f5d9a87"
integrity sha512-pN8Tt43XuLamN+bspAZ9tEMGDp1bOfaxluYop1/qmNRQmM5BOelFqr4jRvARD6y/7iuhLjOEjMQgy5HweXN7Kg==
dependencies:
"@open-draft/until" "^1.0.3"
debug "^4.1.1"
Expand Down

0 comments on commit 55d0255

Please sign in to comment.