Skip to content

Commit

Permalink
build: rename package types into model
Browse files Browse the repository at this point in the history
  • Loading branch information
pvcnt committed Aug 23, 2024
1 parent 80ea1f2 commit 2d624b2
Show file tree
Hide file tree
Showing 33 changed files with 67 additions and 64 deletions.
2 changes: 1 addition & 1 deletion apps/webapp/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"@blueprintjs/icons": "^5.9.0",
"@blueprintjs/select": "^5.1.5",
"@repo/github": "workspace:*",
"@repo/types": "workspace:*",
"@repo/model": "workspace:*",
"clsx": "^2.1.1",
"comlink": "^4.4.1",
"dexie": "^4.0.7",
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/components/CommandBar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { useMemo, useState } from "react";
import { HotkeysTarget2, HotkeyConfig, MenuItem } from "@blueprintjs/core";
import { ItemPredicate, ItemRenderer, Omnibar } from "@blueprintjs/select";
import type { Pull } from "@repo/types";
import type { Pull } from "@repo/model";
import { usePulls } from "../lib/queries";

type Props = {
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/components/ConnectionDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Dialog, DialogBody, DialogFooter, FormGroup, HTMLSelect, InputGroup, Intent } from "@blueprintjs/core"
import { useState } from "react"
import ConfirmDialog from "./ConfirmDialog"
import type { ConnectionProps } from "@repo/types";
import type { ConnectionProps } from "@repo/model";
import { isTruthy } from "remeda";
import { AppToaster } from "../lib/toaster";

Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/components/ConnectionTable.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, HTMLTable } from "@blueprintjs/core"
import { useState } from "react"
import ConnectionDialog from "./ConnectionDialog"
import type { Connection, ConnectionProps } from "@repo/types"
import type { Connection, ConnectionProps } from "@repo/model"

import styles from "./ConnectionTable.module.scss";

Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/components/DashboardSection.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Button, Card, Collapse, H5, Icon, Intent, Spinner, Tag } from "@blueprintjs/core"
import { useState } from "react"
import SectionDialog from "./SectionDialog";
import type { Pull, Section } from "@repo/types";
import type { Pull, Section } from "@repo/model";
import PullTable from "./PullTable";

import styles from "./DashboardSection.module.scss";
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/components/PullTable.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { HTMLTable, Tooltip, Tag, Icon } from "@blueprintjs/core";
import ReactTimeAgo from "react-time-ago";
import { type Pull, PullState } from "@repo/types";
import { type Pull, PullState } from "@repo/model";
import IconWithTooltip from "./IconWithTooltip";
import { computeSize } from "../lib/size";

Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/components/SectionDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Button, Checkbox, Dialog, DialogBody, DialogFooter, FormGroup, InputGro
import { useState } from "react";
import { AppToaster } from "../lib/toaster"
import ConfirmDialog from "./ConfirmDialog";
import { type SectionProps, defaultSectionProps } from "@repo/types";
import { type SectionProps, defaultSectionProps } from "@repo/model";

type Props = {
title: string,
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/lib/db.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Connection, Pull, Section, Star } from "@repo/types";
import type { Connection, Pull, Section, Star } from "@repo/model";
import Dexie, { type EntityTable } from "dexie";

export type Activity = {
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/lib/mutations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { db } from "./db";
import { defaultSections, type Connection, type Pull, type Section } from "@repo/types";
import { defaultSections, type Connection, type Pull, type Section } from "@repo/model";
import { omit } from "remeda";

export async function saveConnection (value: Connection): Promise<void> {
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/lib/queries.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { db } from "./db";
import { useLiveQuery } from "dexie-react-hooks";
import { defaultSections } from "@repo/types";
import { defaultSections } from "@repo/model";

// Defaults to populate after adding new fields.
const connectionDefaults = { orgs: [] };
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/lib/size.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { reverse, zip } from "remeda";
import type { PullProps } from "@repo/types"
import type { PullProps } from "@repo/model"

// Defaults come from Prow:
// https://github.com/kubernetes/test-infra/blob/master/prow/plugins/size/size.go
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/routes/dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useSearchParams } from "react-router-dom";
import { Button } from "@blueprintjs/core";
import SectionDialog from "../components/SectionDialog";
import DashboardSection from "../components/DashboardSection";
import { type Section, type SectionProps, defaultSectionProps } from "@repo/types";
import { type Section, type SectionProps, defaultSectionProps } from "@repo/model";
import { useSections, usePulls } from "../lib/queries";
import { deleteSection, moveSectionDown, moveSectionUp, saveSection, toggleStar } from "../lib/mutations";
import Navbar from "../components/Navbar";
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/src/routes/settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import ConfirmDialog from "../components/ConfirmDialog";
import { getWorker } from "../worker/client";
import { useConnections } from "../lib/queries";
import { deleteConnection, resetSections, saveConnection } from "../lib/mutations";
import type { Connection, ConnectionProps } from "@repo/types"
import type { Connection, ConnectionProps } from "@repo/model"
import styles from "./settings.module.scss";
import { AppToaster } from "../lib/toaster";
import { useNavigate } from "react-router-dom";
Expand Down
5 changes: 3 additions & 2 deletions apps/webapp/src/worker/instance.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import * as Comlink from "comlink";
import { groupBy, unique } from "remeda";
import { db } from "../lib/db";
import { splitQueries, type Pull, type Connection } from "@repo/github";
import { splitQueries } from "@repo/github";
import type { Pull, Connection } from "@repo/model";
import { GitHubClient, isInAttentionSet } from "@repo/github";
import { gitHubClient } from "../github";

Expand All @@ -18,7 +19,7 @@ function syncViewers(client: GitHubClient) {

async function executeActivity(name: string, intervalMillis: number, force: boolean, fn: () => Promise<void>): Promise<void> {
const activity = await db.activities.get(name);
if (!force && activity !== undefined && activity.refreshTime <= new Date(Date.now() - intervalMillis)) {
if (!force && activity !== undefined && activity.refreshTime > new Date(Date.now() - intervalMillis)) {
return;
}
if (activity === undefined) {
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/tests/components/ConnectionDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { render, screen } from "@testing-library/react";
import { userEvent, type UserEvent } from "@testing-library/user-event";
import ConnectionDialog from "../../src/components/ConnectionDialog.js";
import { AppToaster } from "../../src/lib/toaster.js";
import type { ConnectionProps } from "@repo/types";
import type { ConnectionProps } from "@repo/model";
import { mockConnection } from "@repo/testing";

describe("connection dialog", () => {
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/tests/lib/db.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { test, expect } from "vitest";
import { Activity, db } from "../../src/lib/db.js";
import type { Star } from "@repo/types";
import type { Star } from "@repo/model";
import { mockConnection, mockSection, mockPull } from "@repo/testing";

test("db should save a connection", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
import { TestGitHubClient } from "@repo/github";
import { afterEach, beforeEach, it, describe, expect, assert } from "vitest";
import { syncPullsOnce, syncViewersOnce } from "./instance";
import { db } from "../lib/db";
import { syncPullsOnce, syncViewersOnce } from "../../src/worker/instance.js";
import { db } from "../../src/lib/db.js";
import { mockPull, mockConnection, mockSection } from "@repo/testing";

describe("sync viewers", () => {
let client: TestGitHubClient|undefined;

beforeEach(async () => {
client = new TestGitHubClient();
await db.connections.add(mockConnection({ id: "1" }));
await db.connections.add(mockConnection({ id: "2" }));
})
Expand All @@ -19,38 +16,39 @@ describe("sync viewers", () => {
})

it("should update connections", async () => {
assert(client !== undefined);
let activity = await db.activities.get("syncViewers");
expect(activity).toBeUndefined();

const client = new TestGitHubClient();
await syncViewersOnce(client);

let connection = await db.connections.get("1");
expect(connection).toBeDefined();
expect(connection?.viewer).toBeDefined();
expect(connection?.viewer?.user).toEqual({ name: "test[1]", avatarUrl: "" });

connection = await db.connections.get("2");
expect(connection?.viewer).toBeDefined();
expect(connection?.viewer?.user).toEqual({ name: "test[2]", avatarUrl: "" });
})

it("should update activity", async () => {
assert(client !== undefined);

let activity = await db.activities.get("syncViewers");
expect(activity).toBeUndefined();

await syncViewersOnce(client);

activity = await db.activities.get("syncViewers");
expect(activity?.running).toBeFalsy();
expect(activity?.refreshTime.getTime()).toBeGreaterThan(0);
expect(activity?.refreshTime.getTime()).toBeLessThanOrEqual(Date.now());
})

it("should not update connections if recently completed", async () => {
await db.activities.add({ name: "syncViewers", running: false, refreshTime: new Date() });

const client = new TestGitHubClient();
await syncViewersOnce(client);

const connection = await db.connections.get("1");
expect(connection?.viewer).toBeUndefined();
})
})

describe("sync pulls", () => {
let client: TestGitHubClient|undefined;

beforeEach(async () => {
client = new TestGitHubClient();
await db.connections.add(mockConnection({ id: "1" }));
await db.connections.add(mockConnection({ id: "2" }));
await db.sections.add(mockSection({ id: "1", search: "author:@me draft:true;author:@me draft:false" }));
Expand All @@ -65,11 +63,14 @@ describe("sync pulls", () => {
})

it("should update pulls", async () => {
assert(client !== undefined);
let activity = await db.activities.get("syncPulls");
expect(activity).toBeUndefined();

// GIVEN some pull requests are returned from GitHub.
let connection = await db.connections.get("1");
assert(connection !== undefined);

const client = new TestGitHubClient();
client.setPulls(connection, "author:@me draft:true", [
mockPull({ uid: "1:1" }),
mockPull({ uid: "1:2" }),
Expand Down Expand Up @@ -110,19 +111,20 @@ describe("sync pulls", () => {

pull = await db.pulls.get("1:4");
expect(pull?.sections).toEqual(["1"]);
})

it("should update activity", async () => {
assert(client !== undefined);

let activity = await db.activities.get("syncPulls");
expect(activity).toBeUndefined();

await syncPullsOnce(client);

// THEN the activity should have been updated.
activity = await db.activities.get("syncPulls");
expect(activity?.running).toBeFalsy();
expect(activity?.refreshTime.getTime()).toBeGreaterThan(0);
expect(activity?.refreshTime.getTime()).toBeLessThanOrEqual(Date.now());
})

it("should not update pulls if recently completed", async () => {
await db.activities.add({ name: "syncPulls", running: false, refreshTime: new Date() });

const client = new TestGitHubClient();
await syncPullsOnce(client);

expect(await db.pulls.count()).toBe(0);
})
})
2 changes: 1 addition & 1 deletion packages/github/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@
"dependencies": {
"@octokit/core": "^6.1.2",
"@octokit/rest": "^20.1.1",
"@repo/types": "workspace:*"
"@repo/model": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/github/src/attention.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Attention, type PullProps, type Comment, type Connection, PullState } from "@repo/types";
import { type Attention, type PullProps, type Comment, type Connection, PullState } from "@repo/model";
import { GitHubClient } from "./client.js";

export async function isInAttentionSet(client: GitHubClient, connection: Connection, pull: PullProps): Promise<Attention> {
Expand Down
2 changes: 1 addition & 1 deletion packages/github/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Octokit } from "@octokit/rest";
import { type Connection, type Comment, PullState, type PullProps, type Team, type User, type Profile } from "@repo/types";
import { type Connection, type Comment, PullState, type PullProps, type Team, type User, type Profile } from "@repo/model";
import { SearchQuery } from "./search.js";

const MAX_PULLS_TO_FETCH = 50;
Expand Down
2 changes: 1 addition & 1 deletion packages/github/tests/attention.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, it, expect, beforeEach } from "vitest";
import { isInAttentionSet } from "../src/attention.js";
import { TestGitHubClient } from "../src/client.js";
import { mockConnection, mockPull } from "@repo/testing";
import { PullState } from "@repo/types";
import { PullState } from "@repo/model";

describe("attention set", () => {
const client = new TestGitHubClient();
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/types/README.md → packages/model/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# packages/types
# packages/model

This package contains common Typescript types.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "@repo/types",
"name": "@repo/model",
"version": "0.0.0",
"type": "module",
"exports": {
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"lint": "eslint \"**/*.ts\""
},
"dependencies": {
"@repo/types": "workspace:*"
"@repo/model": "workspace:*"
},
"devDependencies": {
"@repo/eslint-config": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/testing/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type Pull, type Section, type Connection, PullState } from "@repo/types";
import { type Pull, type Section, type Connection, PullState } from "@repo/model";

export function mockPull(props?: Partial<Pull>): Pull {
return {
Expand Down
20 changes: 10 additions & 10 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 2d624b2

Please sign in to comment.