From a15cd9c1279003411b5bdd26b72cafa323f555b5 Mon Sep 17 00:00:00 2001 From: Jordan Santell Date: Tue, 4 Mar 2025 11:59:15 -0800 Subject: [PATCH] chore: Fix remaining lints, add to CI --- .github/workflows/lint.yml | 33 +++++++++++++++++++ typescript/packages/common-cli/arena.ts | 10 +++--- typescript/packages/common-cli/gmail.tsx | 2 +- .../common-html/test/html-recipes.test.tsx | 2 +- typescript/packages/common-memory/consumer.ts | 4 +-- typescript/packages/common-memory/entity.ts | 12 +++---- .../packages/common-memory/interface.ts | 32 +++++++++--------- typescript/packages/common-memory/receipt.ts | 12 +++---- .../packages/common-memory/test/space-test.ts | 2 +- .../common-memory/test/stress-debug.ts | 2 -- .../src/components/common-google-oauth.ts | 10 +++--- 11 files changed, 76 insertions(+), 45 deletions(-) create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..2c019e122 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,33 @@ +name: Lint + +on: + push: + branches: + - main + pull_request: + branches: + - main + +jobs: + test: + runs-on: ubuntu-latest + timeout-minutes: 10 + defaults: + run: + working-directory: ./typescript/packages + steps: + - uses: actions/checkout@v4 + - name: Setup Deno + uses: denoland/setup-deno@v2 + with: + deno-version: "2.2.2" + - name: Cache dependencies + uses: actions/cache@v3 + with: + path: | + ~/.deno + ~/.cache/deno + key: ${{ runner.os }}-deno-${{ hashFiles('**/deno.json') }} + - name: Lint + working-directory: typescript/packages + run: deno lint diff --git a/typescript/packages/common-cli/arena.ts b/typescript/packages/common-cli/arena.ts index 2d5536baa..88e40eecf 100644 --- a/typescript/packages/common-cli/arena.ts +++ b/typescript/packages/common-cli/arena.ts @@ -73,11 +73,11 @@ export class ArenaClient { return response.json(); } - async getChannel(slug: string): Promise { + getChannel(slug: string): Promise { return this.fetch(`/channels/${slug}`); } - async getChannelContents( + getChannelContents( slug: string, params: { page?: number; per?: number } = {}, ): Promise { @@ -91,7 +91,7 @@ export class ArenaClient { ); } - async createChannel( + createChannel( params: { title: string; status?: Channel["status"] }, ): Promise { return this.fetch("/channels", { @@ -100,7 +100,7 @@ export class ArenaClient { }); } - async updateChannel( + updateChannel( slug: string, params: { title?: string; @@ -123,7 +123,7 @@ export class ArenaClient { }); } - async getCollaborators(slug: string): Promise { + getCollaborators(slug: string): Promise { return this.fetch(`/channels/${slug}/collaborators`); } } diff --git a/typescript/packages/common-cli/gmail.tsx b/typescript/packages/common-cli/gmail.tsx index 99627fdab..5f116b3ca 100644 --- a/typescript/packages/common-cli/gmail.tsx +++ b/typescript/packages/common-cli/gmail.tsx @@ -78,7 +78,7 @@ const updateLimit = handler<{ detail: { value: string } }, { limit: number }>( ); const googleUpdater = handler< - {}, + NonNullable, { emails: Email[]; auth: Auth; settings: { labels: string; limit: number } } >((_event, state) => { console.log("googleUpdater!"); diff --git a/typescript/packages/common-html/test/html-recipes.test.tsx b/typescript/packages/common-html/test/html-recipes.test.tsx index f0505000b..9eb5f6f1d 100644 --- a/typescript/packages/common-html/test/html-recipes.test.tsx +++ b/typescript/packages/common-html/test/html-recipes.test.tsx @@ -42,7 +42,7 @@ describe("recipes with HTML", () => {

{title}

    - {items.map((item) =>
  • {item.title}
  • )} + {items.map((item, i) =>
  • {item.title}
  • )}
), diff --git a/typescript/packages/common-memory/consumer.ts b/typescript/packages/common-memory/consumer.ts index bb27fa2a5..29c850c0d 100644 --- a/typescript/packages/common-memory/consumer.ts +++ b/typescript/packages/common-memory/consumer.ts @@ -152,7 +152,7 @@ class MemoryConsumerSession< if (command.the === "task/return") { const invocation = this.invocations.get(id); this.invocations.delete(id); - invocation?.return(command.is as {}); + invocation?.return(command.is as NonNullable); } // If it is an effect it can be for one specific subscription, yet we may // have other subscriptions that will be affected. There for we simply // pass effect to each one and they can detect if it concerns them. @@ -301,7 +301,7 @@ class ConsumerInvocation { this.promise = new Promise>( (resolve) => (receive = resolve), ); - this.return = receive as typeof receive & {}; + this.return = receive as typeof receive & NonNullable; } refer() { diff --git a/typescript/packages/common-memory/entity.ts b/typescript/packages/common-memory/entity.ts index b32a15ab2..4cf01da0f 100644 --- a/typescript/packages/common-memory/entity.ts +++ b/typescript/packages/common-memory/entity.ts @@ -1,6 +1,6 @@ import { fromJSON, refer } from "merkle-reference"; -export interface Entity { +export interface Entity> { "@": ToString>; } @@ -9,16 +9,16 @@ export interface Entity { */ export type ToString = string & { toString(): ToString }; -export const entity = ( - description: {} | null, +export const entity = >( + description: NonNullable | null, ): Entity => { return { "@": refer(description).toJSON()["/"] }; }; -export const toString = (entity: Entity): string => +export const toString = >(entity: Entity): string => `@${entity["@"]}`; -export const fromString = ( +export const fromString = >( source: string | ToString>, ): Entity => { if (!source.startsWith("@")) { @@ -37,7 +37,7 @@ export const fromString = ( /** * Asserts type of the `source` to be an `Entity`. */ -export const is = ( +export const is = >( source: unknown | Entity, ): source is Entity => source != null && typeof (source as { ["@"]?: string })["@"] === "string"; diff --git a/typescript/packages/common-memory/interface.ts b/typescript/packages/common-memory/interface.ts index aafcc4b6a..001a57c69 100644 --- a/typescript/packages/common-memory/interface.ts +++ b/typescript/packages/common-memory/interface.ts @@ -80,7 +80,7 @@ export interface AuthorizationError extends Error { export type Call< Ability extends The = The, Of extends DID = DID, - Args extends {} = {}, + Args extends NonNullable = NonNullable, > = { cmd: Ability; sub: Of; @@ -91,7 +91,7 @@ export type Call< export type Command< Ability extends The = The, Of extends DID = DID, - In extends {} = {}, + In extends NonNullable = NonNullable, > = { cmd: Ability; sub: Of; @@ -103,7 +103,7 @@ export type Command< export type Invocation< Ability extends The = The, Of extends DID = DID, - In extends {} = {}, + In extends NonNullable = NonNullable, > = { iss: DID; aud?: DID; @@ -161,7 +161,7 @@ export type Protocol = { export type Proto = { [Subject: DID]: { - [Namespace: string]: {}; + [Namespace: string]: NonNullable; }; }; @@ -175,8 +175,8 @@ export type InferProtoMethods< Prefix extends string = "", > = { [Name in keyof Methods & string]: Methods[Name] extends ( - input: infer In extends {}, - ) => Task ? + input: infer In extends NonNullable, + ) => Task, infer Effect> ? | { [The in `${Prefix}/${Name}`]: Method< Protocol, @@ -195,8 +195,8 @@ export type InferProtoMethods< export type Method< Protocol, Ability extends The, - In extends {}, - Out extends {}, + In extends NonNullable, + Out extends NonNullable, Effect, > = { The: Ability; @@ -243,7 +243,7 @@ type UnionToIntersection = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never; -export type Provider = { +export type Provider> = { perform(command: ProviderCommand): AwaitResult; }; @@ -341,7 +341,7 @@ export type ConsumerResultFor = MethodFor< export interface InvocationView< Source extends Invocation, - Return extends {}, + Return extends NonNullable, Effect, > extends Invocation { return(result: Await): void; @@ -353,8 +353,8 @@ export interface InvocationView< export type Task = Iterable; export type Job< - Command extends {} = {}, - Return extends {} | null = {} | null, + Command extends NonNullable = NonNullable, + Return extends NonNullable | null = NonNullable | null, Effect = unknown, > = { invoke: Command; @@ -378,7 +378,7 @@ export type SessionTask = | UnwatchTask | WatchTask; -export type Receipt = +export type Receipt, Result extends NonNullable | null, Effect> = | { the: "task/return"; of: InvocationURL>; @@ -391,13 +391,13 @@ export type Receipt = is: Effect; }); -export type Effect = { +export type Effect, Command> = { of: Reference; run: Command; is?: undefined; }; -export type Return = { +export type Return, Result extends NonNullable | null> = { of: Reference; is: Result; run?: undefined; @@ -730,7 +730,7 @@ export type Selection = { [space in Space]: FactSelection; }; -export type Unit = {}; +export type Unit = NonNullable; /** * Generic type used to annotate underlying type with a context of the replica. diff --git a/typescript/packages/common-memory/receipt.ts b/typescript/packages/common-memory/receipt.ts index c2f5f39c2..9e83fca67 100644 --- a/typescript/packages/common-memory/receipt.ts +++ b/typescript/packages/common-memory/receipt.ts @@ -3,20 +3,20 @@ import { Receipt } from "./interface.ts"; /** * Formats receipt to a string representation. */ -export const toString = ( +export const toString = , Result extends NonNullable, Effect>( receipt: Receipt, ) => JSON.stringify(receipt); /** * Parses receipt from a string representation. */ -export const fromString = ( +export const fromString = , Result extends NonNullable, Effect>( source: string, ): Receipt => JSON.parse(source); export const fromStringStream = < - Command extends {}, - Result extends {}, + Command extends NonNullable, + Result extends NonNullable, Effect, >() => new TransformStream>({ @@ -26,8 +26,8 @@ export const fromStringStream = < }); export const toStringStream = < - Command extends {}, - Result extends {}, + Command extends NonNullable, + Result extends NonNullable, Effect, >() => new TransformStream, string>({ diff --git a/typescript/packages/common-memory/test/space-test.ts b/typescript/packages/common-memory/test/space-test.ts index 82c0218c7..666f39d8f 100644 --- a/typescript/packages/common-memory/test/space-test.ts +++ b/typescript/packages/common-memory/test/space-test.ts @@ -1018,7 +1018,7 @@ test( }, ); -test("list empty store", DB, async (session) => { +test("list empty store", DB, (session) => { const result = session.query({ cmd: "/memory/query", iss: alice.did(), diff --git a/typescript/packages/common-memory/test/stress-debug.ts b/typescript/packages/common-memory/test/stress-debug.ts index 07cfc4f09..d0dad67d5 100644 --- a/typescript/packages/common-memory/test/stress-debug.ts +++ b/typescript/packages/common-memory/test/stress-debug.ts @@ -1,5 +1,3 @@ -// @ts-nocheck - import { assert, assertEquals, diff --git a/typescript/packages/common-ui/src/components/common-google-oauth.ts b/typescript/packages/common-ui/src/components/common-google-oauth.ts index 6026d2e3e..bad6e22e0 100644 --- a/typescript/packages/common-ui/src/components/common-google-oauth.ts +++ b/typescript/packages/common-ui/src/components/common-google-oauth.ts @@ -47,7 +47,7 @@ export class CommonGoogleOauthElement extends LitElement { // Create a message listener for the OAuth callback const messageListener = (event: MessageEvent) => { // Verify origin for security - if (event.origin !== window.location.origin) return; + if (event.origin !== globalThis.location.origin) return; if (event.data && event.data.type === "oauth-callback") { console.log("Received OAuth callback data:", event.data); @@ -56,14 +56,14 @@ export class CommonGoogleOauthElement extends LitElement { ? "Authentication successful!" : `Authentication failed: ${event.data.result.error || "Unknown error"}`; this.isLoading = false; - window.removeEventListener("message", messageListener); + globalThis.removeEventListener("message", messageListener); } }; - window.addEventListener("message", messageListener); + globalThis.addEventListener("message", messageListener); // Open the OAuth window - const authWindow = window.open(resp.url, "_blank", "width=800,height=600,left=200,top=200"); + const authWindow = globalThis.open(resp.url, "_blank", "width=800,height=600,left=200,top=200"); // Check for window closure if (authWindow) { @@ -74,7 +74,7 @@ export class CommonGoogleOauthElement extends LitElement { this.authStatus = "OAuth window closed. Authentication may not have completed."; this.isLoading = false; } - window.removeEventListener("message", messageListener); + globalThis.removeEventListener("message", messageListener); } }, 500); }