Skip to content

Commit

Permalink
Fix optional napi interface opt check.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnspurlock-skymethod committed Dec 2, 2023
1 parent 64f13c7 commit 5f49b7c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ export function checkOptionalFunction(name: string, value: unknown): asserts val
if (!(value === undefined || typeof value === 'function')) throw new TypeError(`Bad '${name}': expected optional function, found ${value}`);
}

export function checkObject(name: string, value: unknown): asserts value is object {
if (typeof value !== 'object') throw new TypeError(`Bad '${name}': expected object, found ${value}`);
export function checkOptionalObject(name: string, value: unknown): asserts value is object {
if (!(value === undefined || typeof value === 'object')) throw new TypeError(`Bad '${name}': expected optional object, found ${value}`);
}

export function check(name: string, value: unknown, valid: boolean) {
Expand Down
4 changes: 2 additions & 2 deletions src/napi_based.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { checkObject, checkOptionalBoolean, checkOptionalFunction, checkOptionalString, checkRecord, isRecord } from './check.ts';
import { checkOptionalBoolean, checkOptionalFunction, checkOptionalObject, checkOptionalString, checkRecord, isRecord } from './check.ts';
import { decodeAtomicWriteOutput, decodeSnapshotReadOutput, encodeAtomicWrite, encodeSnapshotRead } from './kv_connect_api.ts';
import { packKey } from './kv_key.ts';
import { KvConsistencyLevel, KvEntryMaybe, KvKey, KvService } from './kv_types.ts';
Expand Down Expand Up @@ -79,7 +79,7 @@ class NapiBasedKv extends ProtoBasedKv {
checkOptionalString('url', url);
checkRecord('opts', opts);
checkOptionalBoolean('opts.debug', opts.debug);
checkObject('opts.napi', opts.napi);
checkOptionalObject('opts.napi', opts.napi);
checkOptionalFunction('opts.decodeV8', opts.decodeV8);
checkOptionalFunction('opts.encodeV8', opts.encodeV8);
checkOptionalBoolean('opts.inMemory', opts.inMemory);
Expand Down

0 comments on commit 5f49b7c

Please sign in to comment.