diff options
Diffstat (limited to 'cli/js')
-rw-r--r-- | cli/js/deno.ts | 2 | ||||
-rw-r--r-- | cli/js/lib.deno.ns.d.ts | 34 | ||||
-rw-r--r-- | cli/js/ops/plugins.ts | 12 | ||||
-rw-r--r-- | cli/js/plugins.ts | 64 |
4 files changed, 15 insertions, 97 deletions
diff --git a/cli/js/deno.ts b/cli/js/deno.ts index 0322bac27..e35e8c161 100644 --- a/cli/js/deno.ts +++ b/cli/js/deno.ts @@ -93,7 +93,7 @@ export { PermissionStatus, Permissions, } from "./permissions.ts"; -export { openPlugin } from "./plugins.ts"; +export { openPlugin } from "./ops/plugins.ts"; export { kill } from "./ops/process.ts"; export { run, RunOptions, Process, ProcessStatus } from "./process.ts"; export { DirEntry, readdirSync, readdir } from "./ops/fs/read_dir.ts"; diff --git a/cli/js/lib.deno.ns.d.ts b/cli/js/lib.deno.ns.d.ts index 06baf3aa2..119ba781e 100644 --- a/cli/js/lib.deno.ns.d.ts +++ b/cli/js/lib.deno.ns.d.ts @@ -1796,35 +1796,23 @@ declare namespace Deno { * Requires `allow-write` permission. */ export function truncate(name: string, len?: number): Promise<void>; - export interface AsyncHandler { - (msg: Uint8Array): void; - } - - export interface PluginOp { - dispatch( - control: Uint8Array, - zeroCopy?: ArrayBufferView | null - ): Uint8Array | null; - setAsyncHandler(handler: AsyncHandler): void; - } - - export interface Plugin { - ops: { - [name: string]: PluginOp; - }; - } - /** **UNSTABLE**: new API, yet to be vetted. * * Open and initalize a plugin. * - * const plugin = Deno.openPlugin("./path/to/some/plugin.so"); - * const some_op = plugin.ops.some_op; - * const response = some_op.dispatch(new Uint8Array([1,2,3,4])); + * const rid = Deno.openPlugin("./path/to/some/plugin.so"); + * const opId = Deno.core.ops()["some_op"]; + * const response = Deno.core.dispatch(opId, new Uint8Array([1,2,3,4])); * console.log(`Response from plugin ${response}`); * - * Requires `allow-plugin` permission. */ - export function openPlugin(filename: string): Plugin; + * Requires `allow-plugin` permission. + * + * The plugin system is not stable and will change in the future, hence the + * lack of docs. For now take a look at the example + * https://github.com/denoland/deno/tree/master/test_plugin + */ + export function openPlugin(filename: string): number; + export interface NetAddr { transport: "tcp" | "udp"; hostname: string; diff --git a/cli/js/ops/plugins.ts b/cli/js/ops/plugins.ts index 878ea1c66..e4593afbb 100644 --- a/cli/js/ops/plugins.ts +++ b/cli/js/ops/plugins.ts @@ -1,12 +1,6 @@ import { sendSync } from "./dispatch_json.ts"; -interface OpenPluginResponse { - rid: number; - ops: { - [name: string]: number; - }; -} - -export function openPlugin(filename: string): OpenPluginResponse { - return sendSync("op_open_plugin", { filename }); +export function openPlugin(filename: string): number { + const rid = sendSync("op_open_plugin", { filename }); + return rid; } diff --git a/cli/js/plugins.ts b/cli/js/plugins.ts deleted file mode 100644 index 498da8e16..000000000 --- a/cli/js/plugins.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { openPlugin as openPluginOp } from "./ops/plugins.ts"; -import { core } from "./core.ts"; -import { close } from "./ops/resources.ts"; - -export interface AsyncHandler { - (msg: Uint8Array): void; -} - -interface PluginOp { - dispatch( - control: Uint8Array, - zeroCopy?: ArrayBufferView | null - ): Uint8Array | null; - setAsyncHandler(handler: AsyncHandler): void; -} - -class PluginOpImpl implements PluginOp { - readonly #opId: number; - - constructor(opId: number) { - this.#opId = opId; - } - - dispatch( - control: Uint8Array, - zeroCopy?: ArrayBufferView | null - ): Uint8Array | null { - return core.dispatch(this.#opId, control, zeroCopy); - } - - setAsyncHandler(handler: AsyncHandler): void { - core.setAsyncHandler(this.#opId, handler); - } -} - -interface Plugin { - ops: { - [name: string]: PluginOp; - }; - close(): void; -} - -class PluginImpl implements Plugin { - #ops: { [name: string]: PluginOp } = {}; - - constructor(readonly rid: number, ops: { [name: string]: number }) { - for (const op in ops) { - this.#ops[op] = new PluginOpImpl(ops[op]); - } - } - - get ops(): { [name: string]: PluginOp } { - return Object.assign({}, this.#ops); - } - - close(): void { - close(this.rid); - } -} - -export function openPlugin(filename: string): Plugin { - const response = openPluginOp(filename); - return new PluginImpl(response.rid, response.ops); -} |