Skip to content

Commit

Permalink
📦 Update unknownutil to v4
Browse files Browse the repository at this point in the history
  • Loading branch information
lambdalisue committed Aug 2, 2024
1 parent 8c920ec commit a00f8a2
Show file tree
Hide file tree
Showing 10 changed files with 63 additions and 40 deletions.
7 changes: 5 additions & 2 deletions denops/@denops-private/denops.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type { Context, Denops, Dispatcher, Meta } from "jsr:@denops/core@7.0.0";
import { BatchError } from "jsr:@denops/core@7.0.0";
import { ensure, is } from "jsr:@core/unknownutil@3.18.1";
import { ensure } from "jsr:@core/unknownutil@^4.0.0/ensure";
import { isTupleOf } from "jsr:@core/unknownutil@^4.0.0/is/tuple-of";
import { isArray } from "jsr:@core/unknownutil@^4.0.0/is/array";
import { isString } from "jsr:@core/unknownutil@^4.0.0/is/string";
import type { Host as HostOrigin } from "./host.ts";
import type { Service as ServiceOrigin } from "./service.ts";

const isBatchReturn = is.TupleOf([is.Array, is.String] as const);
const isBatchReturn = isTupleOf([isArray, isString] as const);

export type Host = Pick<HostOrigin, "redraw" | "call" | "batch">;

Expand Down
4 changes: 2 additions & 2 deletions denops/@denops-private/error.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { is } from "jsr:@core/unknownutil@3.18.1";
import { isString } from "jsr:@core/unknownutil@^4.0.0/is/string";
import {
fromErrorObject,
isErrorObject,
Expand All @@ -16,7 +16,7 @@ export function errorSerializer(err: unknown): unknown {
}

export function errorDeserializer(err: unknown): unknown {
if (is.String(err)) {
if (isString(err)) {
const obj = tryOr(() => JSON.parse(err), undefined);
if (isErrorObject(obj)) {
return fromErrorObject(obj);
Expand Down
2 changes: 1 addition & 1 deletion denops/@denops-private/error_test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { assert, assertEquals, assertInstanceOf } from "jsr:@std/assert@1.0.1";
import { is } from "jsr:@core/unknownutil@3.18.1";
import { is } from "jsr:@core/unknownutil@^4.0.0";
import { errorDeserializer, errorSerializer } from "./error.ts";

Deno.test("errorSerializer", async (t) => {
Expand Down
24 changes: 15 additions & 9 deletions denops/@denops-private/host.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { ensure, is, type Predicate } from "jsr:@core/unknownutil@3.18.1";
import type { Predicate } from "jsr:@core/unknownutil@^4.0.0/type";
import { ensure } from "jsr:@core/unknownutil@^4.0.0/ensure";
import { asOptional } from "jsr:@core/unknownutil@^4.0.0/as/optional";
import { isArray } from "jsr:@core/unknownutil@^4.0.0/is/array";
import { isParametersOf } from "jsr:@core/unknownutil@^4.0.0/is/parameters-of";
import { isString } from "jsr:@core/unknownutil@^4.0.0/is/string";
import { isUnknown } from "jsr:@core/unknownutil@^4.0.0/is/unknown";

/**
* Host (Vim/Neovim) which is visible from Service
Expand Down Expand Up @@ -94,15 +100,15 @@ export function invoke(
}

const serviceMethodArgs = {
load: is.ParametersOf([is.String, is.String] as const),
unload: is.ParametersOf([is.String] as const),
reload: is.ParametersOf([is.String] as const),
interrupt: is.ParametersOf([is.OptionalOf(is.Unknown)] as const),
dispatch: is.ParametersOf([is.String, is.String, is.Array] as const),
dispatchAsync: is.ParametersOf(
[is.String, is.String, is.Array, is.String, is.String] as const,
load: isParametersOf([isString, isString] as const),
unload: isParametersOf([isString] as const),
reload: isParametersOf([isString] as const),
interrupt: isParametersOf([asOptional(isUnknown)] as const),
dispatch: isParametersOf([isString, isString, isArray] as const),
dispatchAsync: isParametersOf(
[isString, isString, isArray, isString, isString] as const,
),
close: is.ParametersOf([] as const),
close: isParametersOf([] as const),
} as const satisfies {
[K in keyof ServiceForInvoke]: Predicate<Parameters<ServiceForInvoke[K]>>;
};
24 changes: 15 additions & 9 deletions denops/@denops-private/host/nvim.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
import { ensure, is } from "jsr:@core/unknownutil@3.18.1";
import { ensure } from "jsr:@core/unknownutil@^4.0.0/ensure";
import { isArray } from "jsr:@core/unknownutil@^4.0.0/is/array";
import { isNull } from "jsr:@core/unknownutil@^4.0.0/is/null";
import { isNumber } from "jsr:@core/unknownutil@^4.0.0/is/number";
import { isString } from "jsr:@core/unknownutil@^4.0.0/is/string";
import { isTupleOf } from "jsr:@core/unknownutil@^4.0.0/is/tuple-of";
import { isUnionOf } from "jsr:@core/unknownutil@^4.0.0/is/union-of";
import { Client, Session } from "jsr:@lambdalisue/messagepack-rpc@2.4.0";
import { errorDeserializer, errorSerializer } from "../error.ts";
import { getVersionOr } from "../version.ts";
Expand Down Expand Up @@ -27,8 +33,8 @@ export class Neovim implements Host {
}
return invoke(
this.#service,
ensure(method, is.String),
ensure(args, is.Array),
ensure(method, isString),
ensure(args, isArray),
);
},

Expand Down Expand Up @@ -130,16 +136,16 @@ export class Neovim implements Host {
// nvim_call_function throws a special error object
// https://github.com/neovim/neovim/blob/5dc0bdfe98b59bb03226167ed541d17cc5af30b1/src/nvim/api/vimscript.c#L260
// https://github.com/neovim/neovim/blob/5dc0bdfe98b59bb03226167ed541d17cc5af30b1/src/nvim/api/private/defs.h#L63-L66
const isNvimErrorObject = is.TupleOf([is.Number, is.String] as const);
const isNvimErrorObject = isTupleOf([isNumber, isString] as const);

// nvim_call_atomics returns a tuple of [return values, error details]
const isNvimCallAtomicReturn = is.TupleOf(
const isNvimCallAtomicReturn = isTupleOf(
[
is.Array,
is.OneOf([
is.Null,
isArray,
isUnionOf([
isNull,
// the index, the error type, the error message
is.TupleOf([is.Number, is.Number, is.String] as const),
isTupleOf([isNumber, isNumber, isString] as const),
]),
] as const,
);
21 changes: 13 additions & 8 deletions denops/@denops-private/host/vim.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
import { ensure, is } from "jsr:@core/unknownutil@3.18.1";
import { ensure } from "jsr:@core/unknownutil@^4.0.0/ensure";
import { isArray } from "jsr:@core/unknownutil@^4.0.0/is/array";
import { isLiteralOf } from "jsr:@core/unknownutil@^4.0.0/is/literal-of";
import { isString } from "jsr:@core/unknownutil@^4.0.0/is/string";
import { isTupleOf } from "jsr:@core/unknownutil@^4.0.0/is/tuple-of";
import { isUnknown } from "jsr:@core/unknownutil@^4.0.0/is/unknown";
import {
Client,
type Message,
Expand Down Expand Up @@ -120,16 +125,16 @@ export class Vim implements Host {
}
}

const isCallReturn = is.TupleOf([is.Unknown, is.String] as const);
const isCallReturn = isTupleOf([isUnknown, isString] as const);

const isBatchReturn = is.TupleOf([is.Array, is.String] as const);
const isBatchReturn = isTupleOf([isArray, isString] as const);

const isVoidMessage = is.TupleOf([is.LiteralOf("void")] as const);
const isVoidMessage = isTupleOf([isLiteralOf("void")] as const);

const isInvokeMessage = is.TupleOf(
const isInvokeMessage = isTupleOf(
[
is.LiteralOf("invoke"),
is.String,
is.Array,
isLiteralOf("invoke"),
isString,
isArray,
] as const,
);
2 changes: 1 addition & 1 deletion denops/@denops-private/host_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {
assertSpyCalls,
stub,
} from "jsr:@std/testing@1.0.0-rc.5/mock";
import { AssertError } from "jsr:@core/unknownutil@3.18.1";
import { AssertError } from "jsr:@core/unknownutil@^4.0.0";
import { unimplemented } from "jsr:@lambdalisue/errorutil@1.1.0";
import { invoke, type Service } from "./host.ts";

Expand Down
15 changes: 9 additions & 6 deletions denops/@denops-private/util.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import type { Meta } from "jsr:@denops/core@7.0.0";
import { is, type Predicate } from "jsr:@core/unknownutil@3.18.1";
import type { Predicate } from "jsr:@core/unknownutil@^4.0.0/type";
import { isLiteralOneOf } from "jsr:@core/unknownutil@^4.0.0/is/literal-one-of";
import { isObjectOf } from "jsr:@core/unknownutil@^4.0.0/is/object-of";
import { isString } from "jsr:@core/unknownutil@^4.0.0/is/string";

export const isMeta: Predicate<Meta> = is.ObjectOf({
mode: is.LiteralOneOf(["release", "debug", "test"] as const),
host: is.LiteralOneOf(["vim", "nvim"] as const),
version: is.String,
platform: is.LiteralOneOf(["windows", "mac", "linux"] as const),
export const isMeta: Predicate<Meta> = isObjectOf({
mode: isLiteralOneOf(["release", "debug", "test"] as const),
host: isLiteralOneOf(["vim", "nvim"] as const),
version: isString,
platform: isLiteralOneOf(["windows", "mac", "linux"] as const),
});
2 changes: 1 addition & 1 deletion denops/@denops-private/version_test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { assert, assertEquals } from "jsr:@std/assert@1.0.1";
import { resolvesNext, stub } from "jsr:@std/testing@1.0.0-rc.5/mock";
import type { SemVer } from "jsr:@std/semver@0.224.3/types";
import { is, type Predicate } from "jsr:@core/unknownutil@3.18.1";
import { is, type Predicate } from "jsr:@core/unknownutil@^4.0.0";
import { getVersionOr } from "./version.ts";

Deno.test("getVersionOr()", async (t) => {
Expand Down
2 changes: 1 addition & 1 deletion denops/@denops-private/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
readableStreamFromWorker,
writableStreamFromWorker,
} from "jsr:@lambdalisue/workerio@4.0.1";
import { ensure } from "jsr:@core/unknownutil@3.18.1";
import { ensure } from "jsr:@core/unknownutil@^4.0.0/ensure";
import { pop } from "jsr:@lambdalisue/streamtools@1.0.0";
import { asyncSignal } from "jsr:@milly/async-signal@^1.0.0";
import type { Meta } from "jsr:@denops/core@7.0.0";
Expand Down

0 comments on commit a00f8a2

Please sign in to comment.