Skip to content

Commit

Permalink
Update imports and generated schema types
Browse files Browse the repository at this point in the history
  • Loading branch information
zephraph committed Jan 26, 2025
1 parent 0bd635e commit f70f836
Show file tree
Hide file tree
Showing 6 changed files with 478 additions and 7 deletions.
3 changes: 3 additions & 0 deletions src/clients/deno/deno.lock

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

12 changes: 5 additions & 7 deletions src/clients/deno/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,16 @@
*/

import { EventEmitter } from "node:events";
import {
WebViewMessage,
type WebViewOptions,
type WebViewRequest,
WebViewResponse,
} from "./schemas.ts";
import { WebViewMessage } from "./schemas/WebViewMessage.ts";
import type { WebViewOptions } from "./schemas/WebViewOptions.ts";
import type { WebViewRequest } from "./schemas/WebViewRequest.ts";
import { WebViewResponse } from "./schemas/WebViewResponse.ts";
import { monotonicUlid as ulid } from "jsr:@std/ulid";
import type { Except, Simplify } from "npm:type-fest";
import { join } from "jsr:@std/path";
import { ensureDir, exists } from "jsr:@std/fs";

export type { WebViewOptions } from "./schemas.ts";
export type { WebViewOptions } from "./schemas/WebViewOptions.ts";

// Should match the cargo package version
/** The version of the webview binary that's expected */
Expand Down
128 changes: 128 additions & 0 deletions src/clients/deno/schemas/WebViewMessage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// DO NOT EDIT: This file is auto-generated by generate-schema/index.ts
import { z } from "npm:zod";

/**
* Messages that are sent unbidden from the webview to the client.
*/
export type Notification =
| {
$type: "started";
/** The version of the webview binary */
version: string;
}
| {
$type: "ipc";
/** The message sent from the webview UI to the client. */
message: string;
}
| {
$type: "closed";
};

/**
* Types that can be returned from webview results.
*/
export type ResultType =
| {
$type: "string";

value: string;
}
| {
$type: "boolean";

value: boolean;
}
| {
$type: "float";

value: number;
}
| {
$type: "size";

value: {
/** The height of the window in logical pixels. */
height: number;
/** The ratio between physical and logical sizes. */
scale_factor: number;
/** The width of the window in logical pixels. */
width: number;
};
};

/**
* Responses from the webview to the client.
*/
export type Response =
| {
$type: "ack";

id: string;
}
| {
$type: "result";

id: string;

result: ResultType;
}
| {
$type: "err";

id: string;

message: string;
};

/**
* Complete definition of all outbound messages from the webview to the client.
*/
export type WebViewMessage =
| {
$type: "notification";

data: Notification;
}
| {
$type: "response";

data: Response;
};

export const Notification: z.ZodType<Notification> = z.discriminatedUnion(
"$type",
[
z.object({ $type: z.literal("started"), version: z.string() }),
z.object({ $type: z.literal("ipc"), message: z.string() }),
z.object({ $type: z.literal("closed") }),
],
);

export const ResultType: z.ZodType<ResultType> = z.discriminatedUnion("$type", [
z.object({ $type: z.literal("string"), value: z.string() }),
z.object({ $type: z.literal("boolean"), value: z.boolean() }),
z.object({ $type: z.literal("float"), value: z.number() }),
z.object({
$type: z.literal("size"),
value: z.object({
height: z.number(),
scale_factor: z.number(),
width: z.number(),
}),
}),
]);

export const Response: z.ZodType<Response> = z.discriminatedUnion("$type", [
z.object({ $type: z.literal("ack"), id: z.string() }),
z.object({ $type: z.literal("result"), id: z.string(), result: ResultType }),
z.object({ $type: z.literal("err"), id: z.string(), message: z.string() }),
]);

export const WebViewMessage: z.ZodType<WebViewMessage> = z.discriminatedUnion(
"$type",
[
z.object({ $type: z.literal("notification"), data: Notification }),
z.object({ $type: z.literal("response"), data: Response }),
],
);
101 changes: 101 additions & 0 deletions src/clients/deno/schemas/WebViewOptions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// DO NOT EDIT: This file is auto-generated by generate-schema/index.ts
import { z } from "npm:zod";

export type WindowSizeStates = "maximized" | "fullscreen";
export type WindowSize = WindowSizeStates | {
height: number;
width: number;
};

/**
* Options for creating a webview.
*/
export type WebViewOptions =
& {
/** Sets whether clicking an inactive window also clicks through to the webview. Default is false. */
acceptFirstMouse?: boolean;
/** When true, all media can be played without user interaction. Default is false. */
autoplay?: boolean;
/**
* Enables clipboard access for the page rendered on Linux and Windows.
*
* macOS doesn’t provide such method and is always enabled by default. But your app will still need to add menu item accelerators to use the clipboard shortcuts.
*/
clipboard?: boolean;
/** When true, the window will have a border, a title bar, etc. Default is true. */
decorations?: boolean;
/**
* Enable or disable webview devtools.
*
* Note this only enables devtools to the webview. To open it, you can call `webview.open_devtools()`, or right click the page and open it from the context menu.
*/
devtools?: boolean;
/** Sets whether the webview should be focused when created. Default is false. */
focused?: boolean;
/**
* Run the WebView with incognito mode. Note that WebContext will be ingored if incognito is enabled.
*
* Platform-specific: - Windows: Requires WebView2 Runtime version 101.0.1210.39 or higher, does nothing on older versions, see https://learn.microsoft.com/en-us/microsoft-edge/webview2/release-notes/archive?tabs=dotnetcsharp#10121039
*/
incognito?: boolean;
/** Run JavaScript code when loading new pages. When the webview loads a new page, this code will be executed. It is guaranteed that the code is executed before window.onload. */
initializationScript?: string;
/** Sets whether host should be able to receive messages from the webview via `window.ipc.postMessage`. */
ipc?: boolean;
/** The size of the window. */
size?: WindowSize;
/** Sets the title of the window. */
title: string;
/** Sets whether the window should be transparent. */
transparent?: boolean;
/** Sets the user agent to use when loading pages. */
userAgent?: string;
}
& (
| {
/** Optional headers to send with the request. */
headers?: Record<string, string>;
/** Url to load in the webview. Note: Don't use data URLs here, as they are not supported. Use the `html` field instead. */
url: string;
}
| {
/** Html to load in the webview. */
html: string;
/** What to set as the origin of the webview when loading html. */
origin?: string;
}
);

export const WindowSizeStates: z.ZodType<WindowSizeStates> = z.enum([
"maximized",
"fullscreen",
]);
export const WindowSize: z.ZodType<WindowSize> = z.union([
WindowSizeStates,
z.object({ height: z.number(), width: z.number() }),
]);

export const WebViewOptions: z.ZodType<WebViewOptions> = z.intersection(
z.object({
acceptFirstMouse: z.boolean().optional(),
autoplay: z.boolean().optional(),
clipboard: z.boolean().optional(),
decorations: z.boolean().optional(),
devtools: z.boolean().optional(),
focused: z.boolean().optional(),
incognito: z.boolean().optional(),
initializationScript: z.string(),
ipc: z.boolean().optional(),
size: WindowSize.optional(),
title: z.string(),
transparent: z.boolean().optional(),
userAgent: z.string(),
}),
z.union([
z.object({
headers: z.record(z.string(), z.string()).optional(),
url: z.string(),
}),
z.object({ html: z.string(), origin: z.string() }),
]),
);
Loading

0 comments on commit f70f836

Please sign in to comment.