Skip to content

Commit

Permalink
Refactor - just moving files into directories.
Browse files Browse the repository at this point in the history
  • Loading branch information
aboodman committed Dec 10, 2021
1 parent 444fca6 commit 6a366bf
Show file tree
Hide file tree
Showing 30 changed files with 59 additions and 61 deletions.
File renamed without changes.
2 changes: 1 addition & 1 deletion backend/data.ts → backend/db/data.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JSONValue } from "replicache";
import { ZodSchema } from "zod";
import { Executor, transact } from "./pg";
import { RoomID } from "./room-state";
import { RoomID } from "../types/room-state";

export async function createDatabase() {
await transact(async (executor) => {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { expect } from "chai";
import { setup, test } from "mocha";
import { PatchOperation } from "replicache";
import { createDatabase } from "./data";
import { withExecutor } from "./pg";
import { createDatabase } from "../db/data";
import { withExecutor } from "../db/pg";
import { getPatch } from "./get-patch";
import { NullableVersion } from "./version";
import { ReplicacheTransaction } from "./replicache-transaction";
import { EntryCache } from "./entry-cache";
import { DBStorage } from "./db-storage";
import { NullableVersion } from "../types/version";
import { ReplicacheTransaction } from "../storage/replicache-transaction";
import { EntryCache } from "../storage/entry-cache";
import { DBStorage } from "../storage/db-storage";

setup(async () => {
await withExecutor(async () => {
Expand Down
8 changes: 4 additions & 4 deletions backend/get-patch.ts → backend/fastforward/get-patch.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { z } from "zod";
import { Patch } from "../protocol/poke";
import { Executor } from "./pg";
import { userValuePrefix, userValueSchema } from "./user-value";
import { NullableVersion } from "./version";
import { Patch } from "../../protocol/poke";
import { Executor } from "../db/pg";
import { userValuePrefix, userValueSchema } from "../types/user-value";
import { NullableVersion } from "../types/version";

export async function getPatch(
executor: Executor,
Expand Down
2 changes: 1 addition & 1 deletion backend/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Command } from "commander";
import { createServer, IncomingMessage, Server as NodeServer } from "http";
import { WebSocket } from "ws";
import { parse } from "url";
import { Socket } from "./client-state";
import { Socket } from "./types/client-state";
import { Server } from "./server";

const dev = process.env.NODE_ENV !== "production";
Expand Down
8 changes: 4 additions & 4 deletions backend/process/process-mutation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import {
ClientRecord,
getClientRecord,
putClientRecord,
} from "../client-record";
import { MemStorage } from "../mem-storage";
import { clientRecord, mutation } from "../test-utils";
} from "../types/client-record";
import { MemStorage } from "../storage/mem-storage";
import { clientRecord, mutation } from "../util/test-utils";
import { expect } from "chai";
import { test } from "mocha";
import { JSONType } from "protocol/json";
import { Mutation } from "protocol/push";
import { WriteTransaction } from "replicache";
import { MutatorMap, processMutation } from "./process-mutation";
import { getUserValue } from "../user-value";
import { getUserValue } from "../types/user-value";

test("processMutation", async () => {
type Case = {
Expand Down
12 changes: 6 additions & 6 deletions backend/process/process-mutation.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Mutation } from "../../protocol/push";
import { ReplicacheTransaction } from "../replicache-transaction";
import { Version } from "../version";
import { Storage } from "../storage";
import { EntryCache } from "../entry-cache";
import { getClientRecord, putClientRecord } from "../client-record";
import { ClientID } from "../client-state";
import { ReplicacheTransaction } from "../storage/replicache-transaction";
import { Version } from "../types/version";
import { Storage } from "../storage/storage";
import { EntryCache } from "../storage/entry-cache";
import { getClientRecord, putClientRecord } from "../types/client-record";
import { ClientID } from "../types/client-state";

export type Mutator = (tx: ReplicacheTransaction, args: any) => Promise<void>;
export type MutatorMap = Map<string, Mutator>;
Expand Down
12 changes: 6 additions & 6 deletions backend/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import {
ClientRecord,
clientRecordKey,
clientRecordSchema,
} from "./client-record";
import { createDatabase, getEntry, putEntry } from "./data";
import { transact, withExecutor } from "./pg";
} from "./types/client-record";
import { createDatabase, getEntry, putEntry } from "./db/data";
import { transact, withExecutor } from "./db/pg";
import { Server } from "./server";
import { RoomMap } from "./room-state";
import { Socket } from "./client-state";
import { RoomMap } from "./types/room-state";
import { Socket } from "./types/client-state";
import { Mutation } from "../protocol/push";
import {
client,
Expand All @@ -19,7 +19,7 @@ import {
room,
roomMap,
sleep,
} from "./test-utils";
} from "./util/test-utils";

setup(async () => {
await withExecutor(async () => {
Expand Down
14 changes: 7 additions & 7 deletions backend/server.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { parse } from "url";
import { RoomID, RoomMap } from "./room-state";
import { Lock } from "./lock";
import { ClientID, ClientState, Socket } from "./client-state";
import { RoomID, RoomMap } from "./types/room-state";
import { Lock } from "./util/lock";
import { ClientID, ClientState, Socket } from "./types/client-state";
import {
clientRecordKey,
clientRecordSchema,
ClientRecord,
} from "./client-record";
import { DBStorage } from "./db-storage";
import { transact } from "./pg";
} from "./types/client-record";
import { DBStorage } from "./storage/db-storage";
import { transact } from "./db/pg";
import { PushBody } from "../protocol/push";
import { sendError } from "./socket";
import { sendError } from "./util/socket";
import { upstreamSchema } from "../protocol/up";

export type Now = () => number;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { transact, withExecutor } from "./pg";
import { transact, withExecutor } from "../db/pg";
import { expect } from "chai";
import { setup, test } from "mocha";
import { DBStorage } from "./db-storage";
import { createDatabase, getEntry } from "./data";
import { createDatabase, getEntry } from "../db/data";
import { z } from "zod";
import { resolver } from "../frontend/resolver";
import { resolver } from "../../frontend/resolver";

setup(async () => {
await withExecutor(async () => {
Expand Down
6 changes: 3 additions & 3 deletions backend/db-storage.ts → backend/storage/db-storage.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { JSONValue } from "replicache";
import { delEntry, getEntry, putEntry } from "./data";
import { Executor } from "./pg";
import { Version } from "./version";
import { delEntry, getEntry, putEntry } from "../db/data";
import { Executor } from "../db/pg";
import { Version } from "../types/version";
import type { Storage } from "./storage";
import { ZodSchema } from "zod";

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { transact } from "./pg";
import { transact } from "../db/pg";
import { expect } from "chai";
import { test } from "mocha";
import { EntryCache } from "./entry-cache";
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { ReplicacheTransaction } from "./replicache-transaction";
import { transact, withExecutor } from "./pg";
import { transact, withExecutor } from "../db/pg";
import { expect } from "chai";
import { setup, test } from "mocha";
import { EntryCache } from "./entry-cache";
import { DBStorage } from "./db-storage";
import { createDatabase, getEntry } from "./data";
import { UserValue, userValueKey, userValueSchema } from "./user-value";
import { createDatabase, getEntry } from "../db/data";
import { UserValue, userValueKey, userValueSchema } from "../types/user-value";
import { MemStorage } from "./mem-storage";

test("ReplicacheTransaction", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { JSONValue, ScanResult, WriteTransaction } from "replicache";
import { Version } from "./version";
import { Version } from "../types/version";
import { EntryCache } from "./entry-cache";
import { UserValue, userValueKey, userValueSchema } from "./user-value";
import { UserValue, userValueKey, userValueSchema } from "../types/user-value";
import { JSONType } from "protocol/json";
import { ClientID } from "./client-state";
import { ClientID } from "../types/client-state";

/**
* Implements Replicache's WriteTransaction in terms of EntryCache.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { nullableVersionSchema } from "./version";
import { z } from "zod";
import { ClientID } from "./client-state";
import { Storage } from "./storage";
import { Storage } from "../storage/storage";

export const clientRecordSchema = z.object({
lastMutationID: z.number(),
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions backend/user-value.ts → backend/types/user-value.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { jsonSchema } from "../protocol/json";
import { jsonSchema } from "../../protocol/json";
import { versionSchema } from "./version";
import { Storage } from "./storage";
import { Storage } from "../storage/storage";
import { z } from "zod";

export const userValueSchema = z.object({
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion backend/lock.test.ts → backend/util/lock.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { expect } from "chai";
import { test } from "mocha";
import { resolver } from "../frontend/resolver";
import { resolver } from "../../frontend/resolver";
import { Lock } from "./lock";
import { sleep } from "./test-utils";

Expand Down
2 changes: 1 addition & 1 deletion backend/lock.ts → backend/util/lock.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolver } from "../frontend/resolver";
import { resolver } from "../../frontend/resolver";

// This is lifted from Replicache. Perhaps should be refactored into shared repo?
// Same with resolver.ts.
Expand Down
2 changes: 1 addition & 1 deletion backend/socket.ts → backend/util/socket.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Downstream } from "protocol/down";
import { Socket } from "./client-state";
import { Socket } from "../types/client-state";

export function sendError(ws: Socket, body: string) {
const message: Downstream = ["error", body];
Expand Down
6 changes: 3 additions & 3 deletions backend/test-utils.ts → backend/util/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { JSONType } from "protocol/json";
import { Mutation } from "protocol/push";
import { ClientID, ClientState, Socket } from "./client-state";
import { RoomID, RoomMap, RoomState } from "./room-state";
import { NullableVersion } from "./version";
import { ClientID, ClientState, Socket } from "../types/client-state";
import { RoomID, RoomMap, RoomState } from "../types/room-state";
import { NullableVersion } from "../types/version";

export function roomMap(...rooms: [RoomID, RoomState][]): RoomMap {
return new Map(rooms);
Expand Down
2 changes: 1 addition & 1 deletion pages/api/init.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createDatabase } from "../../backend/data";
import { createDatabase } from "../../backend/db/data";
import type { NextApiRequest, NextApiResponse } from "next";

export default async (req: NextApiRequest, res: NextApiResponse) => {
Expand Down
2 changes: 0 additions & 2 deletions pages/d/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { randUserInfo } from "../../frontend/client-state";
import { randomShape } from "../../frontend/shape";
import { PushMessage, PushBody } from "../../protocol/push";
import { resolver } from "frontend/resolver";
import { nanoid } from "nanoid";
import { pokeMessageSchema } from "protocol/poke";

export default function Home() {
Expand All @@ -31,7 +30,6 @@ export default function Home() {
pusher: async (req) => {
const ws = await socket;
const pushBody = (await req.json()) as PushBody;
pushBody.id = nanoid();
const msg: PushMessage = ["push", pushBody];
ws.send(JSON.stringify(msg));
return {
Expand Down
2 changes: 1 addition & 1 deletion protocol/poke.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { nullableVersionSchema, versionSchema } from "backend/version";
import { nullableVersionSchema, versionSchema } from "backend/types/version";
import { z } from "zod";
import { jsonSchema } from "./json";

Expand Down

0 comments on commit 6a366bf

Please sign in to comment.