Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 5 additions & 5 deletions typescript/packages/common-cli/arena.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ export class ArenaClient {
return response.json();
}

async getChannel(slug: string): Promise<Channel> {
getChannel(slug: string): Promise<Channel> {
return this.fetch<Channel>(`/channels/${slug}`);
}

async getChannelContents(
getChannelContents(
slug: string,
params: { page?: number; per?: number } = {},
): Promise<Channel["contents"]> {
Expand All @@ -91,7 +91,7 @@ export class ArenaClient {
);
}

async createChannel(
createChannel(
params: { title: string; status?: Channel["status"] },
): Promise<Channel> {
return this.fetch<Channel>("/channels", {
Expand All @@ -100,7 +100,7 @@ export class ArenaClient {
});
}

async updateChannel(
updateChannel(
slug: string,
params: {
title?: string;
Expand All @@ -123,7 +123,7 @@ export class ArenaClient {
});
}

async getCollaborators(slug: string): Promise<User[]> {
getCollaborators(slug: string): Promise<User[]> {
return this.fetch<User[]>(`/channels/${slug}/collaborators`);
}
}
Expand Down
2 changes: 1 addition & 1 deletion typescript/packages/common-cli/gmail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const updateLimit = handler<{ detail: { value: string } }, { limit: number }>(
);

const googleUpdater = handler<
{},
NonNullable<unknown>,
{ emails: Email[]; auth: Auth; settings: { labels: string; limit: number } }
>((_event, state) => {
console.log("googleUpdater!");
Expand Down
2 changes: 1 addition & 1 deletion typescript/packages/common-html/test/html-recipes.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ describe("recipes with HTML", () => {
<div>
<h1>{title}</h1>
<ul>
{items.map((item) => <li>{item.title}</li>)}
{items.map((item, i) => <li key={i.toString()}>{item.title}</li>)}
</ul>
</div>
),
Expand Down
4 changes: 2 additions & 2 deletions typescript/packages/common-memory/consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown>);
} // 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.
Expand Down Expand Up @@ -301,7 +301,7 @@ class ConsumerInvocation<Ability extends The, Protocol extends Proto> {
this.promise = new Promise<ConsumerResultFor<Ability, Protocol>>(
(resolve) => (receive = resolve),
);
this.return = receive as typeof receive & {};
this.return = receive as typeof receive & NonNullable<unknown>;
}

refer() {
Expand Down
12 changes: 6 additions & 6 deletions typescript/packages/common-memory/entity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fromJSON, refer } from "merkle-reference";

export interface Entity<T extends null | {}> {
export interface Entity<T extends null | NonNullable<unknown>> {
"@": ToString<Entity<T>>;
}

Expand All @@ -9,16 +9,16 @@ export interface Entity<T extends null | {}> {
*/
export type ToString<T> = string & { toString(): ToString<T> };

export const entity = <T extends null | {}>(
description: {} | null,
export const entity = <T extends null | NonNullable<unknown>>(
description: NonNullable<unknown> | null,
): Entity<T> => {
return { "@": refer(description).toJSON()["/"] };
};

export const toString = <T extends null | {}>(entity: Entity<T>): string =>
export const toString = <T extends null | NonNullable<unknown>>(entity: Entity<T>): string =>
`@${entity["@"]}`;

export const fromString = <T extends null | {}>(
export const fromString = <T extends null | NonNullable<unknown>>(
source: string | ToString<Entity<T>>,
): Entity<T> => {
if (!source.startsWith("@")) {
Expand All @@ -37,7 +37,7 @@ export const fromString = <T extends null | {}>(
/**
* Asserts type of the `source` to be an `Entity`.
*/
export const is = <T extends null | {}>(
export const is = <T extends null | NonNullable<unknown>>(
source: unknown | Entity<T>,
): source is Entity<T> =>
source != null && typeof (source as { ["@"]?: string })["@"] === "string";
32 changes: 16 additions & 16 deletions typescript/packages/common-memory/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<unknown> = NonNullable<unknown>,
> = {
cmd: Ability;
sub: Of;
Expand All @@ -91,7 +91,7 @@ export type Call<
export type Command<
Ability extends The = The,
Of extends DID = DID,
In extends {} = {},
In extends NonNullable<unknown> = NonNullable<unknown>,
> = {
cmd: Ability;
sub: Of;
Expand All @@ -103,7 +103,7 @@ export type Command<
export type Invocation<
Ability extends The = The,
Of extends DID = DID,
In extends {} = {},
In extends NonNullable<unknown> = NonNullable<unknown>,
> = {
iss: DID;
aud?: DID;
Expand Down Expand Up @@ -161,7 +161,7 @@ export type Protocol<Space extends MemorySpace = MemorySpace> = {

export type Proto = {
[Subject: DID]: {
[Namespace: string]: {};
[Namespace: string]: NonNullable<unknown>;
};
};

Expand All @@ -175,8 +175,8 @@ export type InferProtoMethods<
Prefix extends string = "",
> = {
[Name in keyof Methods & string]: Methods[Name] extends (
input: infer In extends {},
) => Task<infer Out extends {}, infer Effect> ?
input: infer In extends NonNullable<unknown>,
) => Task<infer Out extends NonNullable<unknown>, infer Effect> ?
| {
[The in `${Prefix}/${Name}`]: Method<
Protocol,
Expand All @@ -195,8 +195,8 @@ export type InferProtoMethods<
export type Method<
Protocol,
Ability extends The,
In extends {},
Out extends {},
In extends NonNullable<unknown>,
Out extends NonNullable<unknown>,
Effect,
> = {
The: Ability;
Expand Down Expand Up @@ -243,7 +243,7 @@ type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends
(k: infer I) => void ? I
: never;

export type Provider<Protocol extends {}> = {
export type Provider<Protocol extends NonNullable<unknown>> = {
perform(command: ProviderCommand<Protocol>): AwaitResult<Unit, SystemError>;
};

Expand Down Expand Up @@ -341,7 +341,7 @@ export type ConsumerResultFor<Ability, Protocol extends Proto> = MethodFor<

export interface InvocationView<
Source extends Invocation,
Return extends {},
Return extends NonNullable<unknown>,
Effect,
> extends Invocation<Source["cmd"], Source["sub"], Source["args"]> {
return(result: Await<Return>): void;
Expand All @@ -353,8 +353,8 @@ export interface InvocationView<
export type Task<Return, Command = never> = Iterable<Command, Return>;

export type Job<
Command extends {} = {},
Return extends {} | null = {} | null,
Command extends NonNullable<unknown> = NonNullable<unknown>,
Return extends NonNullable<unknown> | null = NonNullable<unknown> | null,
Effect = unknown,
> = {
invoke: Command;
Expand All @@ -378,7 +378,7 @@ export type SessionTask<Space extends MemorySpace> =
| UnwatchTask<Space>
| WatchTask<Space>;

export type Receipt<Command extends {}, Result extends {} | null, Effect> =
export type Receipt<Command extends NonNullable<unknown>, Result extends NonNullable<unknown> | null, Effect> =
| {
the: "task/return";
of: InvocationURL<Reference<Command>>;
Expand All @@ -391,13 +391,13 @@ export type Receipt<Command extends {}, Result extends {} | null, Effect> =
is: Effect;
});

export type Effect<Of extends {}, Command> = {
export type Effect<Of extends NonNullable<unknown>, Command> = {
of: Reference<Of>;
run: Command;
is?: undefined;
};

export type Return<Of extends {}, Result extends {} | null> = {
export type Return<Of extends NonNullable<unknown>, Result extends NonNullable<unknown> | null> = {
of: Reference<Of>;
is: Result;
run?: undefined;
Expand Down Expand Up @@ -730,7 +730,7 @@ export type Selection<Space extends MemorySpace = MemorySpace> = {
[space in Space]: FactSelection;
};

export type Unit = {};
export type Unit = NonNullable<unknown>;

/**
* Generic type used to annotate underlying type with a context of the replica.
Expand Down
12 changes: 6 additions & 6 deletions typescript/packages/common-memory/receipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@ import { Receipt } from "./interface.ts";
/**
* Formats receipt to a string representation.
*/
export const toString = <Command extends {}, Result extends {}, Effect>(
export const toString = <Command extends NonNullable<unknown>, Result extends NonNullable<unknown>, Effect>(
receipt: Receipt<Command, Result, Effect>,
) => JSON.stringify(receipt);

/**
* Parses receipt from a string representation.
*/
export const fromString = <Command extends {}, Result extends {}, Effect>(
export const fromString = <Command extends NonNullable<unknown>, Result extends NonNullable<unknown>, Effect>(
source: string,
): Receipt<Command, Result, Effect> => JSON.parse(source);

export const fromStringStream = <
Command extends {},
Result extends {},
Command extends NonNullable<unknown>,
Result extends NonNullable<unknown>,
Effect,
>() =>
new TransformStream<string, Receipt<Command, Result, Effect>>({
Expand All @@ -26,8 +26,8 @@ export const fromStringStream = <
});

export const toStringStream = <
Command extends {},
Result extends {},
Command extends NonNullable<unknown>,
Result extends NonNullable<unknown>,
Effect,
>() =>
new TransformStream<Receipt<Command, Result, Effect>, string>({
Expand Down
2 changes: 1 addition & 1 deletion typescript/packages/common-memory/test/space-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 0 additions & 2 deletions typescript/packages/common-memory/test/stress-debug.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// @ts-nocheck

import {
assert,
assertEquals,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -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);
}
Expand Down
Loading