Skip to content

Commit

Permalink
Merge pull request #11 from dao-xyz/rewind-3
Browse files Browse the repository at this point in the history
feat: update examples
  • Loading branch information
marcus-pousette authored Oct 20, 2024
2 parents 440e057 + d97a31e commit 28fb03b
Show file tree
Hide file tree
Showing 72 changed files with 7,262 additions and 5,700 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ peerbit/
keystore-test
**/__tests__/**/tmp
/tmp
**/tmp
**/public/peerbit/**
nginx_secrets
nginx
Expand Down
14 changes: 14 additions & 0 deletions .mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"require": ["ts-node/register", "chai-extend/chai-global.js"],
"node-option": [
"experimental-specifier-resolution=node",
"loader=ts-node/esm",
"no-warnings"
],
"extension": ["ts"],
"parallel": false,
"spec": ["**/*.spec.ts", "**/*.test.ts", "**/*.integration.test.ts"],
"ignore": ["**/node_modules/**", "**/dist/**"],
"timeout": "40000",
"exit": true
}
7 changes: 7 additions & 0 deletions chai-global.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { use } from "chai";
import chaiAsPromised from "chai-as-promised";

use(chaiAsPromised);
/*
process.env.TS_NODE_PROJECT = 'tsconfig.test.json';
console.log(process.env.TS_NODE_PROJECT) */
7 changes: 0 additions & 7 deletions global.d.ts

This file was deleted.

29 changes: 0 additions & 29 deletions jest.config.ts

This file was deleted.

17 changes: 10 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,33 +29,36 @@
"build": "lerna run build --reject-cycles",
"build-node": "cd ./packages/node/ && yarn build",
"pub": "lerna publish --no-private",
"test": "node --experimental-vm-modules ./node_modules/.bin/jest test -c jest.config.ts ",
"test": "lerna run test",
"fmt": "prettier --write '{*,**/*}.{js,ts,jsx,tsx,json,vue}'",
"lint": "eslint --ext .ts . && prettier --check '{*,**/*}.{js,ts,jsx,tsx,json,vue}'",
"lint:fix": "eslint --fix --ext .ts . && yarn fmt",
"nuke": "shx rm -rf {.,packages/*/*}/{node_modules,yarn.lock}"
"nuke": "shx rm -rf {.,packages/*/*}/{node_modules,yarn.lock}",
"postinstall": "mkdir -p node_modules/chai-extend && cp chai-global.js node_modules/chai-extend/chai-global.js && echo '{\"type\": \"module\"}' > node_modules/chai-extend/package.json"
},
"devDependencies": {
"@types/eslint": "^8.40.2",
"@types/eslint-plugin-prettier": "^3.1.0",
"@types/jest": "^29.2.3",
"@types/node": "^17.0.32",
"@types/prettier": "^2.4.2",
"@types/chai": "^4.3.18",
"chai": "^5.1.1",
"chai-as-promised": "^8",
"@types/chai-as-promised": "^8",
"eslint": "^8.27.0",
"@types/mocha": "^10.0.7",
"mocha": "^10.7.0",
"@typescript-eslint/eslint-plugin": "^6.16.0",
"@typescript-eslint/parser": "^6.16.0",
"eslint-config-prettier": "^8.5.0",
"eslint-plugin-prettier": "^4.2.1",
"eslint-config-react-app": "^7.0.1",
"prettier": "^2.7.1",
"jest": "^29.7.0",
"jest-extended": "^4.0.2",
"lerna": "^8.0.1",
"shx": "^0.3.4",
"start-server-and-test": "^1.14.0",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"typescript": "^5.3.3",
"typescript": "^5.6.3",
"typescript-esm": "^2.0.0",
"json": "^11.0.0",
"rollup-plugin-copy": "^3.5.0"
Expand Down
6 changes: 2 additions & 4 deletions packages/blog-platform/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@
"scripts": {
"clean": "shx rm -rf lib/*",
"build": "yarn clean && tsc -p tsconfig.json",
"test": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.ts --runInBand --forceExit",
"test:unit": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.unit.ts --runInBand --forceExit",
"test:integration": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.integration.ts --runInBand --forceExit",
"test": "mocha",
"watch": "nodemon"
},
"devDependencies": {
"@types/inquirer": "^9",
"typescript": "^5.3.3"
"typescript": "^5.6.3"
},
"dependencies": {
"@inquirer/editor": "^2",
Expand Down
8 changes: 3 additions & 5 deletions packages/blog-platform/library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,16 @@
"scripts": {
"clean": "shx rm -rf lib/*",
"build": "yarn clean && tsc -p tsconfig.json",
"test": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.ts --runInBand --forceExit",
"test:unit": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.unit.ts --runInBand --forceExit",
"test:integration": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.integration.ts --runInBand --forceExit"
"test": "mocha"
},
"devDependencies": {
"@peerbit/test-utils": "^2",
"typescript": "^5.3.3"
"typescript": "^5.6.3"
},
"dependencies": {
"@peerbit/document": "^7",
"@peerbit/trusted-network": "^4",
"peerbit": "^4",
"uuid": "^9.0.0"
"uuid": "^10.0.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ describe("bootstrap", () => {
let peer: Peerbit;
let peer2: Peerbit;

afterAll(async () => {
after(async () => {
await peer.stop();
await peer2?.stop();
});
Expand Down Expand Up @@ -152,7 +152,7 @@ describe("bootstrap", () => {
const platform = await peer.open(new BlogPosts());
await waitForResolved(() => expect(platform.posts.log.getReplicatorsSorted().length).toBeGreaterThan(1))
await waitForResolved(() => expect(platform.posts.log.getReplicatorsSorted().length).to.be.greaterThan(1))
await platform.alias.put(new Alias({ name: author, publicKey: peer.identity.publicKey }));
for (const post of posts) {
await platform.posts.put(new Post({ title: post.title, content: post.content }));
Expand All @@ -166,7 +166,7 @@ describe("bootstrap", () => {
const platform = await peer.open(new BlogPosts(), { args: { role: 'observer' } });
await peer.bootstrap() // await peer.dial(remoteAddress)
await waitForResolved(() => expect(platform.posts.log.getReplicatorsSorted().length).toBeGreaterThan(0))
await waitForResolved(() => expect(platform.posts.log.getReplicatorsSorted().length).to.be.greaterThan(0))
const posts = await platform.getLatestPosts(1000);
console.log(posts.length) */
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
StringMatchMethod,
StringMatch,
} from "@peerbit/document";
import { expect } from "chai";

describe("index", () => {
let peer: Peerbit, peer2: Peerbit;
Expand All @@ -31,11 +32,10 @@ describe("index", () => {
});
await platform.posts.put(post);

await expect(platform.getPostAuthor(post.id)).resolves.toEqual(
peer.identity.publicKey
);
const result = await platform.getPostAuthor(post.id);
expect(result).to.eq(peer.identity.publicKey);
const myPosts = await platform.getMyPosts();
expect(myPosts).toHaveLength(1);
expect(myPosts).to.have.length(1);

const viewer = await peer2.open<BlogPosts>(platform.address, {
args: { replicate: false },
Expand All @@ -56,15 +56,15 @@ describe("index", () => {
],
})
);
expect(foundPost).toHaveLength(1);
expect(foundPost).to.have.length(1);
});
});

describe("alias", () => {
it("get set", async () => {
const platform = await peer.open(new BlogPosts());
const alias = await platform.getAlias(peer.identity.publicKey);
expect(alias).toBeUndefined();
expect(alias).to.be.undefined;

await platform.alias.put(
new Alias({
Expand All @@ -74,7 +74,7 @@ describe("index", () => {
);

const alias2 = await platform.getAlias(peer.identity.publicKey);
expect(alias2).toBe("Peerbit");
expect(alias2).to.equal("Peerbit");
});
});
});
6 changes: 2 additions & 4 deletions packages/blog-platform/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,12 @@
"clean": "shx rm -rf lib/*",
"build": "yarn clean && tsc -p tsconfig.json",
"start": "ts-node --esm ./src/bin.ts",
"test": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.ts --runInBand --forceExit",
"test:unit": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.unit.ts --runInBand --forceExit",
"test:integration": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.integration.ts --runInBand --forceExit",
"test": "mocha",
"watch": "nodemon"
},
"devDependencies": {
"@peerbit/test-utils": "^2",
"typescript": "^5.3.3",
"typescript": "^5.6.3",
"@types/express": "^4",
"nodemon": "^3"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/collaborative-learning/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
"@emotion/react": "^11.11.3",
"@emotion/styled": "^11.11.0",
"@mui/material": "^5.15.7",
"react-router-dom": "^6.16.0",
"react-router-dom": "^6.27.0",
"@mui/icons-material": "^5.15.7"
},
"devDependencies": {
"@types/react": "^18.2.46",
"@types/react-dom": "^18.2.18",
"@vitejs/plugin-react": "^4",
"typescript": "^5.3.3",
"vite": "^5.3.5",
"typescript": "^5.6.3",
"vite": "^5.4.9",
"@peerbit/vite": "^1"
},
"browserslist": {
Expand Down
6 changes: 2 additions & 4 deletions packages/file-share/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,11 @@
"scripts": {
"clean": "shx rm -rf lib/*",
"build": "yarn clean && tsc -p tsconfig.json",
"test": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.ts --runInBand --forceExit",
"test:unit": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.unit.ts --runInBand --forceExit",
"test:integration": "node ../../../node_modules/.bin/jest test -c ../../../jest.config.integration.ts --runInBand --forceExit"
"test": "mocha"
},
"devDependencies": {
"@peerbit/test-utils": "^2",
"typescript": "^5.3.3"
"typescript": "^5.6.3"
},
"dependencies": {
"@peerbit/please-lib": "^0.0.9",
Expand Down
17 changes: 7 additions & 10 deletions packages/file-share/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-use": "^17.4.0",
"react-router-dom": "^6.16.0",
"react-router-dom": "^6.27.0",
"fast-diff": "^1.3.0",
"react-icons": "^4.10.1",
"faker": "5.5.3",
"react-icons": "^5.3.0",
"@radix-ui/react-toast": "^1.1.4",
"@radix-ui/react-toggle": "^1.0.3",
"@radix-ui/react-slider": "^1.1.2",
Expand All @@ -36,16 +35,14 @@
"chartjs-plugin-datalabels": "^2.2.0"
},
"devDependencies": {
"@types/faker": "5.5.9",
"@types/react": "^18.2.46",
"@types/react-dom": "^18.2.18",
"@vitejs/plugin-react": "^4",
"typescript": "^5.3.3",
"vite": "^5.3.5",
"tailwindcss": "^3.3.3",
"postcss": "^8.4.26",
"autoprefixer": "^10.4.14",
"vite-plugin-static-copy": "^1.0.1",
"typescript": "^5.6.3",
"vite": "^5.4.9",
"tailwindcss": "^3.4.13",
"postcss": "^8.4.47",
"autoprefixer": "^10.4.20",
"@peerbit/vite": "^1"
},
"browserslist": {
Expand Down
10 changes: 4 additions & 6 deletions packages/file-share/frontend/src/Drop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export const Drop = () => {
existing: "reuse",
args: {
replicate: {
limits: { cpu: { max: 0, monitor: undefined as any } },
limits: { cpu: { max: 1, monitor: undefined } },
},
},
}
Expand All @@ -84,7 +84,7 @@ export const Drop = () => {
const [limitStorage, setLimitStorage] = useState<boolean>(false);

const [role, setRole] = useState<"replicator" | "observer">("replicator");
const [limitCPU, setLimitCPU] = useState<number | undefined>(0);
const [limitCPU, setLimitCPU] = useState<number | undefined>(1);
const [uploadProgress, setUploadProgress] = useState<number | null>(null);

// we exclude the string type 'replicator' | 'observer' from the roleOptions so that we can easily serialize it with JSON
Expand All @@ -97,7 +97,7 @@ export const Drop = () => {
saveRoleLocalStorage(files.program, JSON.stringify(roleOptions)); // Save role in localstorage for next time
await files.program.files.log.replicate(false);
if (roleOptions !== false) {
files.program.files.log.replicate(roleOptions);
await files.program.files.log.replicate(roleOptions);
}
};

Expand Down Expand Up @@ -199,7 +199,7 @@ export const Drop = () => {
role === "replicator"
? {
limits: {
cpu: { max: 0, monitor: undefined as any },
cpu: { max: 1, monitor: undefined },
},
}
: false
Expand Down Expand Up @@ -237,7 +237,6 @@ export const Drop = () => {
if (files.program.files.log.closed) {
return;
}
console.log("UPDATE LIST?");

// TODO don't reload the whole list, just add the new elements..
try {
Expand All @@ -264,7 +263,6 @@ export const Drop = () => {
"Failed to resolve complete file list: " + error?.message
);
}
console.log("UPDATE DONE");
};

const download = async (
Expand Down
Loading

0 comments on commit 28fb03b

Please sign in to comment.