Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JSDoc, deno.jsonc, return type tweaks; prep for JSR.io publish test #8

Merged
merged 14 commits into from
Jun 14, 2024
23 changes: 11 additions & 12 deletions deno.jsonc
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
{
"$schema": "https://deno.land/x/deno/cli/schemas/config-file.v1.json",
"name": "@slack/protocols",
"version": "0.0.2",
"exports": "./src/mod.ts",
"fmt": {
"files": {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The files and options keys are deprecated, and deno would warn about using them, so removed them.

"include": ["src", "docs", "README.md"]
},
"options": {
"semiColons": true,
"indentWidth": 2,
"lineWidth": 80,
"proseWrap": "always",
"singleQuote": false,
"useTabs": false
}
"include": ["src", "docs", "README.md"],
"semiColons": true,
"indentWidth": 2,
"lineWidth": 80,
"proseWrap": "always",
"singleQuote": false,
"useTabs": false
},
"lint": {
"files": {
Expand All @@ -26,6 +25,6 @@
"tasks": {
"test": "deno fmt --check && deno lint && deno test --allow-read --allow-net",
"generate-lcov": "rm -rf .coverage && deno test --reporter=dot --allow-read --allow-net --coverage=.coverage && deno coverage --exclude=fixtures --exclude=test --lcov --output=lcov.info .coverage",
"test:coverage": "deno task generate-lcov && deno coverage --exclude=fixtures --exclude=test .coverage src"
"test:coverage": "deno task generate-lcov && deno coverage --detailed --exclude=fixtures --exclude=test .coverage src"
}
}
1 change: 1 addition & 0 deletions src/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { spy } from "./dev_deps.ts";

export const MockProtocol = function (): Protocol {
return {
name: "MockProtocol",
log: spy(),
warn: spy(),
error: spy(),
Expand Down
6 changes: 4 additions & 2 deletions src/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ export const BaseProtocol = function (args: string[]): Protocol {
/**
* Protocol implementation that only uses stdout, but uses message boundaries to differentiate between
* diagnostic information and hook responses.
* @param args command-line arguments passed to this process
* @returns {Protocol}
*/
export const MessageBoundaryProtocol = function (args: string[]): Protocol {
export const MessageBoundaryProtocol = function (args: string[]): Required<Pick<Protocol, 'getCLIFlags'>> & Protocol {
filmaj marked this conversation as resolved.
Show resolved Hide resolved
const { boundary } = parse(
args,
);
Expand Down Expand Up @@ -62,7 +64,7 @@ const PROTOCOL_MAP = {
* Based on the arguments provided by the CLI to the SDK hook process, returns an appropriate Protocol interface
* for communicating with the CLI over the specified protocol.
* @param args string[] An array of strings representing the command-line flags/arguments passed to the hook
* @returns Protocol An object implementing the Protocol interface
* @returns {Protocol} An object implementing the Protocol interface
*/
export const getProtocolInterface = function (args: string[]): Protocol {
const { protocol: protocolRequestedByCLI } = parse(
Expand Down
8 changes: 8 additions & 0 deletions src/tests.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { assertMatch } from "https://deno.land/[email protected]/testing/asserts.ts";
import {
assertEquals,
assertNotEquals,
Expand Down Expand Up @@ -45,6 +46,13 @@ Deno.test("MessageBoundaryProtocol", async (t) => {
globalThis.console.log = origLog;
},
);
await t.step("should return a `getCLIFlags` method that returns correct --protocol and --boundary flags", () => {
const providedFlags = ["--boundary=12345"];
const prot = MessageBoundaryProtocol(providedFlags);
const flags = prot.getCLIFlags();
assertMatch(flags[0], /message-boundaries/);
assertEquals(flags[1], providedFlags[0]);
});
});

Deno.test("getProtocolInterface()", async (t) => {
Expand Down
4 changes: 2 additions & 2 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ export interface Protocol {
warn: typeof console.warn;
/**
* Utility method for responding to CLI hook invocations.
* @param data Stringified JSON to return to the CLI
* @param {data} Stringified JSON to return to the CLI
* @returns
*/
respond: (data: string) => void;
/**
* Retrieve all command-line flags related to the specific protocol implementation. May be useful if child processes are being
* spawned by the SDK, such as in local-run mode of deno-slack-runtime.
* @returns string[] An array of strings representing any protocol-specific command-line flags passed from the CLI to the hook, if applicable
* @returns {string[]} An array of strings representing any protocol-specific command-line flags passed from the CLI to the hook, if applicable
* to the specific protocol implementation
*/
getCLIFlags?: () => string[];
Expand Down
Loading