Skip to content

Commit

Permalink
Cleanup (#254)
Browse files Browse the repository at this point in the history
See commit messages
  • Loading branch information
mweidner037 authored Jul 15, 2023
1 parent 2c26487 commit be87b7a
Show file tree
Hide file tree
Showing 164 changed files with 1,668 additions and 11,888 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ To run commands in the `docs/` folder, also install its Python dependencies: `pi
When installing dependencies, instead of running `npm i <dependency>` in the relevant package's folder, you should run `npm i <dependency> -w <package>` in this top-level folder. That will ensure that the dependency is installed in the workspace's top-level `node_modules` folder, but it is recorded in the correct package's `package.json`. See [https://docs.npmjs.com/cli/v7/using-npm/workspaces#adding-dependencies-to-a-workspace](https://docs.npmjs.com/cli/v7/using-npm/workspaces#adding-dependencies-to-a-workspace).

If you are only making changes to one package, you can skip running `npm i` in this directory and instead do it only in the directory for the package you are working on.

> **Node version** Until [https://github.com/npm/cli/issues/4618](https://github.com/npm/cli/issues/4618) is fixed, you will need to use a slightly old version of NodeJS/npm in order to run top-level commands like `npm run build`. [NodeJS v16.13.1](https://nodejs.org/download/release/v16.13.1/) works.
2 changes: 0 additions & 2 deletions benchmarks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"@types/seedrandom": "^2.4.28",
"@types/uuid": "^8.3.4",
"npm-run-all": "^4.1.5",
"pkg-ok": "^2.3.1",
"prettier": "^2.2.1",
"rimraf": "^2.7.1",
"typescript": "^4.3.5"
Expand All @@ -51,7 +50,6 @@
"build": "npm-run-all build:*",
"build:ts": "tsc -p tsconfig.json",
"test": "npm-run-all test:*",
"test:pkg": "pkg-ok",
"test:format": "prettier --check .",
"fix": "npm-run-all fix:*",
"fix:format": "prettier --write .",
Expand Down
12 changes: 2 additions & 10 deletions benchmarks/run_all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,6 @@ function go {
do
for mode in "rotate" "concurrent"
do
# Skip RealText concurrent mode for now, since Collabs is OOMing and it
# takes a while.
# TODO: undo once it works.
if [ $trace == "RealText" ] && [ $mode == "concurrent" ]
then
echo "Skipping RealText concurrent, see comment"
continue
fi
for measurement in "receiveAll"
do
npm start -- $in1 $in2 $in3 $in4 $measurement $trace $implementation $mode
Expand Down Expand Up @@ -90,8 +82,8 @@ othersMulti=("AutomergeVariable" "YjsVariable")
go

trace="RealText"
oursSingle=("CollabsTextWithCursor" "CollabsRichTextWithCursor")
oursMulti=("CollabsTextWithCursor" "CollabsCGTextWithCursor" "CollabsRichTextWithCursor" "CollabsCGRichTextWithCursor")
oursSingle=("CollabsRichTextWithCursor")
oursMulti=("CollabsRichTextWithCursor" "CollabsCGRichTextWithCursor")
othersSingle=("AutomergeTextWithCursor" "YjsTextWithCursor")
othersMulti=("AutomergeTextWithCursor" "YjsTextWithCursor")
go
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import * as collabs from "@collabs/collabs";
import { CValueMap } from "@collabs/collabs";
import { Data } from "../../../util";
import { IMap } from "../../interfaces/map";
import { CollabsReplica } from "./replica";

export function CollabsMap(causalityGuaranteed: boolean) {
return class CollabsMap extends CollabsReplica implements IMap {
private readonly map: collabs.CValueMap<string, unknown>;
private readonly map: CValueMap<string, unknown>;

constructor(onsend: (msg: Data) => void, replicaIdRng: seedrandom.prng) {
super(onsend, replicaIdRng, causalityGuaranteed);

this.map = this.runtime.registerCollab(
"",
(init) => new collabs.CValueMap(init)
);
this.map = this.runtime.registerCollab("", (init) => new CValueMap(init));
}

set(key: string, value: unknown): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as collabs from "@collabs/collabs";
import { CObject, InitToken } from "@collabs/collabs";
import { Data } from "../../../util";
import { INoop } from "../../interfaces/noop";
import { NoopCRDT } from "./noop";
import { CollabsReplica } from "./replica";

const NESTED_PARENTS = 10;

class NestedNoopCRDT extends collabs.CObject {
class NestedNoopCRDT extends CObject {
private readonly child: NestedNoopCRDT | NoopCRDT;

constructor(init: collabs.InitToken, parentsRemaining: number) {
constructor(init: InitToken, parentsRemaining: number) {
super(init);

if (parentsRemaining === 0) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import * as collabs from "@collabs/collabs";
import { PrimitiveCRDT } from "@collabs/collabs";
import { Data } from "../../../util";
import { INoop } from "../../interfaces/noop";
import { CollabsReplica } from "./replica";

export class NoopCRDT extends collabs.PrimitiveCRDT {
export class NoopCRDT extends PrimitiveCRDT {
noop() {
super.sendPrimitive(new Uint8Array());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import * as collabs from "@collabs/collabs";
import { CRuntime, ReplicaIDs } from "@collabs/collabs";
import { Data } from "../../../util";
import { Replica } from "../../replica_benchmark";

export class CollabsReplica implements Replica {
protected readonly runtime: collabs.CRuntime;
protected readonly runtime: CRuntime;

constructor(
private readonly onsend: (msg: Data) => void,
replicaIdRng: seedrandom.prng,
causalityGuaranteed: boolean
) {
this.runtime = new collabs.CRuntime({
debugReplicaID: collabs.ReplicaIDs.pseudoRandom(replicaIdRng),
this.runtime = new CRuntime({
debugReplicaID: ReplicaIDs.pseudoRandom(replicaIdRng),
causalityGuaranteed,
});
this.runtime.on("Send", (e) => this.onsend(e.message));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as collabs from "@collabs/collabs";
import { CRichText } from "@collabs/collabs";
import { Data } from "../../../util";
import { ITextWithCursor } from "../../interfaces/text_with_cursor";
import { CollabsReplica } from "./replica";
Expand All @@ -8,15 +8,15 @@ export function CollabsRichTextWithCursor(causalityGuaranteed: boolean) {
extends CollabsReplica
implements ITextWithCursor
{
private readonly richText: collabs.CRichText;
private readonly richText: CRichText;
private cursor = -1;

constructor(onsend: (msg: Data) => void, replicaIdRng: seedrandom.prng) {
super(onsend, replicaIdRng, causalityGuaranteed);

this.richText = this.runtime.registerCollab(
"",
(init) => new collabs.CRichText(init)
(init) => new CRichText(init)
);

// Maintain cursor position.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import * as collabs from "@collabs/collabs";
import { CText } from "@collabs/collabs";
import { Data } from "../../../util";
import { IText } from "../../interfaces/text";
import { CollabsReplica } from "./replica";

export function CollabsText(causalityGuaranteed: boolean) {
return class CollabsText extends CollabsReplica implements IText {
private readonly text: collabs.CText;
private readonly text: CText;

constructor(onsend: (msg: Data) => void, replicaIdRng: seedrandom.prng) {
super(onsend, replicaIdRng, causalityGuaranteed);

this.text = this.runtime.registerCollab(
"",
(init) => new collabs.CText(init)
);
this.text = this.runtime.registerCollab("", (init) => new CText(init));
}

insert(index: number, char: string): void {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as collabs from "@collabs/collabs";
import { CText } from "@collabs/collabs";
import { Data } from "../../../util";
import { ITextWithCursor } from "../../interfaces/text_with_cursor";
import { CollabsReplica } from "./replica";
Expand All @@ -8,16 +8,13 @@ export function CollabsTextWithCursor(causalityGuaranteed: boolean) {
extends CollabsReplica
implements ITextWithCursor
{
private readonly text: collabs.CText;
private readonly text: CText;
private cursor = -1;

constructor(onsend: (msg: Data) => void, replicaIdRng: seedrandom.prng) {
super(onsend, replicaIdRng, causalityGuaranteed);

this.text = this.runtime.registerCollab(
"",
(init) => new collabs.CText(init)
);
this.text = this.runtime.registerCollab("", (init) => new CText(init));

// Maintain cursor position.
// We use the fact that all ops are single character insertions/deletions.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import * as collabs from "@collabs/collabs";
import { CBoolean, CList, CObject, CText, InitToken } from "@collabs/collabs";
import { Data } from "../../../util";
import { ITodoList, ITodoListInternal } from "../../interfaces/todo_list";
import { CollabsReplica } from "./replica";

class TodoListInternal extends collabs.CObject implements ITodoListInternal {
private readonly text: collabs.CText;
private readonly doneCollab: collabs.CBoolean;
private readonly items: collabs.CList<TodoListInternal, []>;
class TodoListInternal extends CObject implements ITodoListInternal {
private readonly text: CText;
private readonly doneCollab: CBoolean;
private readonly items: CList<TodoListInternal, []>;

constructor(init: collabs.InitToken) {
constructor(init: InitToken) {
super(init);
this.text = this.registerCollab("text", (init) => new collabs.CText(init));
this.doneCollab = this.registerCollab(
"done",
(init) => new collabs.CBoolean(init)
);
this.text = this.registerCollab("text", (init) => new CText(init));
this.doneCollab = this.registerCollab("done", (init) => new CBoolean(init));
this.items = this.registerCollab(
"items",
(init) =>
new collabs.CList(init, (valueInit) => new TodoListInternal(valueInit))
(init) => new CList(init, (valueInit) => new TodoListInternal(valueInit))
);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import * as collabs from "@collabs/collabs";
import { CVar } from "@collabs/collabs";
import { Data } from "../../../util";
import { IVariable } from "../../interfaces/variable";
import { CollabsReplica } from "./replica";

export function CollabsVariable(causalityGuaranteed: boolean) {
return class CollabsVariable extends CollabsReplica implements IVariable {
private readonly variable: collabs.CVar<unknown>;
private readonly variable: CVar<unknown>;

constructor(onsend: (msg: Data) => void, replicaIdRng: seedrandom.prng) {
super(onsend, replicaIdRng, causalityGuaranteed);

this.variable = this.runtime.registerCollab(
"",
(init) => new collabs.CVar(init, 0)
(init) => new CVar(init, 0)
);
}

Expand Down
5 changes: 1 addition & 4 deletions benchmarks/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
"module": "commonjs",
/* Enable strict type checking. */
"strict": true,
/*
* Necessary for TensorFlow.js.
* See https://www.tensorflow.org/js/tutorials/setup#typescript
*/
/* Prevent errors caused by other libraries. */
"skipLibCheck": true,
/* Enable interop with dependencies using different module systems. */
"esModuleInterop": true,
Expand Down
2 changes: 0 additions & 2 deletions collabs/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ module.exports = {
},
},
],
// I like non-null assertions.
"@typescript-eslint/no-non-null-assertion": "off",
// Disallow default exports; only allow named exports.
"import/no-default-export": "error",
// Impose alphabetically ordered imports.
Expand Down
2 changes: 0 additions & 2 deletions collabs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
"eslint-plugin-import": "~2.24.2",
"mocha": "^9.2.0",
"npm-run-all": "^4.1.5",
"pkg-ok": "^2.3.1",
"prettier": "^2.2.1",
"rimraf": "^2.7.1",
"ts-node": "^10.1.0",
Expand All @@ -65,7 +64,6 @@
"test": "npm-run-all test:*",
"test:lint": "eslint --ext .ts,.js .",
"test:unit": "cross-env TS_NODE_PROJECT='./tsconfig.commonjs.json' TS_NODE_SCOPE=true mocha",
"test:pkg": "pkg-ok",
"test:format": "prettier --check .",
"fix": "npm-run-all fix:*",
"fix:format": "prettier --write .",
Expand Down
17 changes: 9 additions & 8 deletions collabs/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
export {
AbstractList_CObject,
AbstractList_Collab,
AbstractList_CPrimitive,
AbstractList_Collab,
AbstractMap_CObject,
AbstractMap_Collab,
AbstractMap_CPrimitive,
AbstractMap_Collab,
AbstractRuntime,
AbstractSet_CObject,
AbstractSet_Collab,
AbstractSet_CPrimitive,
Bytes,
AbstractSet_Collab,
CConst,
CLazyMap,
CMessenger,
CObject,
CPrimitive,
Collab,
CollabEvent,
CollabEventsRecord,
CollabID,
CPrimitive,
Cursor,
Cursors,
DefaultSerializer,
Expand All @@ -27,11 +26,11 @@ export {
ICursorList,
IList,
IMap,
InitToken,
IParent,
IRuntime,
ISet,
IVar,
InitToken,
ListEvent,
ListEventsRecord,
MapDeleteEvent,
Expand Down Expand Up @@ -63,8 +62,6 @@ export {
CCounter,
CList,
CMap,
CounterAddEvent,
CounterEventsRecord,
CPresence,
CRDTMessageMeta,
CRDTMetaRequest,
Expand All @@ -77,7 +74,11 @@ export {
CValueMap,
CValueSet,
CVar,
CounterAddEvent,
CounterEventsRecord,
ListArchivedEvent,
ListExtendedEventsRecord,
ListMoveArchivedEvent,
ListMoveEvent,
LocalList,
MultiValueMapItem,
Expand Down
21 changes: 1 addition & 20 deletions collabs/test/runtime.test.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
import { assert } from "chai";
import { Bytes, TestingRuntimes } from "../src";

// Reproduce a basic test from @collabs/core to make sure
// everything is loading properly.
describe("core", () => {
describe("Bytes", () => {
it("parse inverts stringify", () => {
const start = new Uint8Array(5);
start.fill(7);

const stringified = Bytes.stringify(start);
const parsed = Bytes.parse(stringified);

assert.isTrue(
Bytes.equals(start, parsed),
`parsed != start (stringified: ${stringified}`
);
});
});
});
import { TestingRuntimes } from "../src";

// Reproduce a basic test from @collabs/crdts to make sure
// everything is loading properly.
Expand Down
7 changes: 1 addition & 6 deletions collabs/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@
"moduleResolution": "node",
/* Enable strict type checking. */
"strict": true,
/* The workspace structure causes tsc to check all
* projects in node_modules during compilation, including
* one tfjs dependency (webgl pinned version) that has
* a bug. So while we are using workspaces, we need
* to skipLibChecks.
*/
/* Prevent errors caused by other libraries. */
"skipLibCheck": true,
/* Enable interop with dependencies using different module systems. */
"esModuleInterop": true,
Expand Down
Loading

0 comments on commit be87b7a

Please sign in to comment.