Skip to content

Commit

Permalink
repo-api,etc: shorten call signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
yoursunny committed Jan 21, 2024
1 parent 360a429 commit 9e29786
Show file tree
Hide file tree
Showing 51 changed files with 110 additions and 109 deletions.
2 changes: 1 addition & 1 deletion integ/browser-tests/tests/autoconfig/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ export interface TestRecord {

declare global {
interface Window {
testConnectToNetwork: () => Promise<TestRecord>;
testConnectToNetwork(): Promise<TestRecord>;
}
}
18 changes: 9 additions & 9 deletions integ/browser-tests/tests/keychain/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ export type SignVerifyTestResult = [

declare global {
interface Window {
testKeyStore: (enabled: KeyStoreEnable) => Promise<KeyStoreRecord>;
testCertStore: () => Promise<CertStoreRecord>;
testDigestSigning: () => Promise<Serialize.Value<SignVerifyTestResult>>;
testECDSA: (curve: EcCurve) => Promise<Serialize.Value<SignVerifyTestResult>>;
testRSA: (modulusLength: RsaModulusLength) => Promise<Serialize.Value<SignVerifyTestResult>>;
testHMAC: () => Promise<Serialize.Value<SignVerifyTestResult>>;
testEd25519: () => Promise<Serialize.Value<SignVerifyTestResult>>;
testSafeBagDecode: (wire: Serialize.Value<Uint8Array>, passphrase: string) => Promise<[sigType: number, certName: string]>;
testSafeBagEncode: (passphrase: string) => Promise<Serialize.Value<Uint8Array>>;
testKeyStore(enabled: KeyStoreEnable): Promise<KeyStoreRecord>;
testCertStore(): Promise<CertStoreRecord>;
testDigestSigning(): Promise<Serialize.Value<SignVerifyTestResult>>;
testECDSA(curve: EcCurve): Promise<Serialize.Value<SignVerifyTestResult>>;
testRSA(modulusLength: RsaModulusLength): Promise<Serialize.Value<SignVerifyTestResult>>;
testHMAC(): Promise<Serialize.Value<SignVerifyTestResult>>;
testEd25519(): Promise<Serialize.Value<SignVerifyTestResult>>;
testSafeBagDecode(wire: Serialize.Value<Uint8Array>, passphrase: string): Promise<[sigType: number, certName: string]>;
testSafeBagEncode(passphrase: string): Promise<Serialize.Value<Uint8Array>>;
}
}
2 changes: 1 addition & 1 deletion integ/browser-tests/tests/segmented-object/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ export interface FetchedInfo {

declare global {
interface Window {
testBlobChunkSource: () => Promise<FetchedInfo>;
testBlobChunkSource(): Promise<FetchedInfo>;
}
}
4 changes: 2 additions & 2 deletions integ/browser-tests/tests/sync/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface UpdateRecord {

declare global {
interface Window {
startPSyncPartial: (uri: string) => Promise<void>;
endPSyncPartial: () => Promise<UpdateRecord[]>;
startPSyncPartial(uri: string): Promise<void>;
endPSyncPartial(): Promise<UpdateRecord[]>;
}
}
4 changes: 2 additions & 2 deletions integ/browser-tests/tests/ws-transport/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { TestRecord } from "@ndn/l3face/test-fixture/transport";

declare global {
interface Window {
connectWsTransportPair: (uri: string) => Promise<void>;
testWsTransportPair: () => Promise<TestRecord>;
connectWsTransportPair(uri: string): Promise<void>;
testWsTransportPair(): Promise<TestRecord>;
}
}
2 changes: 1 addition & 1 deletion packages/autoconfig/src/fch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { FCH_DEFAULTS, fetch } from "./platform_node";
import type { ConnectRouterOptions } from "./router";

export interface PlatformFchDefaults {
transports: (opts?: ConnectRouterOptions) => string[];
transports(opts?: ConnectRouterOptions): string[];
readonly hasIPv4?: boolean;
readonly hasIPv6?: boolean;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/autoconfig/test-fixture/fch-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ export class FchServer {
}

/** Handler of "GET /" request. */
public handle?: (params: URLSearchParams, ctx: Koa.Context) => Promisable<unknown>;
public handle?(params: URLSearchParams, ctx: Koa.Context): Promisable<unknown>;
}
2 changes: 1 addition & 1 deletion packages/cli-common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@ndn/node-transport": "workspace:*",
"@ndn/packet": "workspace:*",
"@ndn/util": "workspace:*",
"dotenv": "^16.3.1",
"dotenv": "^16.3.2",
"env-var": "^7.4.1",
"tslib": "^2.6.2",
"wtfnode": "^0.9.1"
Expand Down
2 changes: 1 addition & 1 deletion packages/dpdkmgmt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
"tslib": "^2.6.2"
},
"optionalDependencies": {
"memif": "0.0.20230715"
"memif": "0.0.20240119"
}
}
8 changes: 4 additions & 4 deletions packages/endpoint/src/data-buffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { signUnsignedData } from "./producer";

/** Outgoing Data buffer for producer. */
export interface DataBuffer {
find: (interest: Interest) => Promise<Data | undefined>;
insert: (...pkts: Data[]) => Promise<void>;
find(interest: Interest): Promise<Data | undefined>;
insert(...pkts: readonly Data[]): Promise<void>;
}

/** Prototype of DataStore from @ndn/repo package. */
interface DataStore {
find: (interest: Interest) => Promise<Data | undefined>;
insert: (opts: { expireTime?: number }, ...pkts: Data[]) => Promise<void>;
find(interest: Interest): Promise<Data | undefined>;
insert(opts: { expireTime?: number }, ...pkts: readonly Data[]): Promise<void>;
}
// We declare an interface here instead of importing DataStore, in order to reduce bundle size for
// webapps that do not use DataBuffer. The trade-off is that, applications wanting to use
Expand Down
6 changes: 3 additions & 3 deletions packages/endpoint/src/producer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ export interface Producer {
* 2. Producer A can invoke this function to let producer B generate a response.
* 3. The response should be sent by producer A.
*/
processInterest: (interest: Interest) => Promise<Data | undefined>;
processInterest(interest: Interest): Promise<Data | undefined>;

/** Close the producer. */
close: () => void;
close(): void;
}

export class ProducerImpl implements Producer {
Expand Down Expand Up @@ -169,7 +169,7 @@ export class ProducerImpl implements Producer {
return found;
}

public close = (): void => {
public readonly close = (): void => {
this.face.close();
this.signal?.removeEventListener("abort", this.close);
};
Expand Down
8 changes: 4 additions & 4 deletions packages/fw/src/face.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ export namespace FwFace {
export interface RxTxBase {
readonly attributes?: Attributes;

addEventListener?: <K extends keyof RxTxEventMap>(type: K, listener: (ev: RxTxEventMap[K]) => any, options?: AddEventListenerOptions) => void;
removeEventListener?: <K extends keyof RxTxEventMap>(type: K, listener: (ev: RxTxEventMap[K]) => any, options?: EventListenerOptions) => void;
addEventListener?<K extends keyof RxTxEventMap>(type: K, listener: (ev: RxTxEventMap[K]) => any, options?: AddEventListenerOptions): void;
removeEventListener?<K extends keyof RxTxEventMap>(type: K, listener: (ev: RxTxEventMap[K]) => any, options?: EventListenerOptions): void;
}

export interface RxTx extends RxTxBase {
rx: AsyncIterable<FwPacket>;
tx: (iterable: AsyncIterable<FwPacket>) => void;
tx(iterable: AsyncIterable<FwPacket>): void;
}

export interface RxTxDuplex extends RxTxBase {
/**
* The transform function takes an iterable of packets sent by the forwarder,
* and returns an iterable of packets received by the forwarder.
*/
duplex: (iterable: AsyncIterable<FwPacket>) => AsyncIterable<FwPacket>;
duplex(iterable: AsyncIterable<FwPacket>): AsyncIterable<FwPacket>;
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/keychain/src/algo/aes-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type { CryptoAlgorithm, EncryptionAlgorithm } from "../key/mod";

export interface AesEncryption<I, G extends AesGenParams> extends EncryptionAlgorithm<I, false, G> {
readonly ivLength: number;
makeAesKeyGenParams: (genParams: G) => AesKeyGenParams;
makeAesKeyGenParams(genParams: G): AesKeyGenParams;
}

export type AesKeyLength = 128 | 192 | 256;
Expand Down
8 changes: 4 additions & 4 deletions packages/keychain/src/key/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export interface NamedSigner<Asym extends boolean = any> extends Key<KeyKind.Pri
readonly sigType: number;

/** Create a Signer that signs with this private key but a different KeyLocator. */
withKeyLocator: (keyLocator: KeyLocator.CtorArg) => Signer;
withKeyLocator(keyLocator: KeyLocator.CtorArg): Signer;
}
export namespace NamedSigner {
/** Named private key signer. */
Expand Down Expand Up @@ -85,15 +85,15 @@ export interface CryptoAlgorithm<I = any, Asym extends boolean = any, G = any> {
{}>;

/** Generate key pair or secret key. */
cryptoGenerate: (params: G, extractable: boolean)
=> Promise<If<Asym, CryptoAlgorithm.GeneratedKeyPair<I>, CryptoAlgorithm.GeneratedSecretKey<I>, never>>;
cryptoGenerate(params: G, extractable: boolean): Promise<
If<Asym, CryptoAlgorithm.GeneratedKeyPair<I>, CryptoAlgorithm.GeneratedSecretKey<I>, never>>;

/**
* Import public key from SPKI.
*
* This should only appear on asymmetric algorithm.
*/
importSpki?: (spki: Uint8Array, der: asn1.ElementBuffer) => Promise<CryptoAlgorithm.PublicKey<I>>;
importSpki?(spki: Uint8Array, der: asn1.ElementBuffer): Promise<CryptoAlgorithm.PublicKey<I>>;
}

export namespace CryptoAlgorithm {
Expand Down
8 changes: 4 additions & 4 deletions packages/keychain/src/store/store-base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ export interface StoreProvider<T> {
*/
readonly canSClone: boolean;

list: () => Promise<string[]>;
get: (key: string) => Promise<T>;
insert: (key: string, value: T) => Promise<void>;
erase: (key: string) => Promise<void>;
list(): Promise<string[]>;
get(key: string): Promise<T>;
insert(key: string, value: T): Promise<void>;
erase(key: string): Promise<void>;
}

/** Memory based KV store provider. */
Expand Down
4 changes: 2 additions & 2 deletions packages/l3face/src/l3face.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export namespace L3Face {
fw?: Forwarder;

/** Routes to be added on the created face. Default is ["/"]. */
addRoutes?: NameLike[];
addRoutes?: readonly NameLike[];

/**
* L3Face attributes.
Expand All @@ -267,7 +267,7 @@ export namespace L3Face {
* A callback to receive Transport, L3Face, and FwFace objects.
* This can be useful for reading counters or listening to events on these objects.
*/
callback?: (transport: Transport, l3face: L3Face, fwFace: FwFace) => void;
callback?(transport: Transport, l3face: L3Face, fwFace: FwFace): void;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions packages/l3face/test-fixture/bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class BridgeTransport extends Transport {
export interface Bridge {
faceA: FwFace;
faceB: FwFace;
close: () => void;
close(): void;
}

function makeRelayFunc(relay: Bridge.Relay): Bridge.RelayFunc {
Expand Down Expand Up @@ -79,8 +79,8 @@ export namespace Bridge {
fwB: Forwarder;
relayAB?: Relay;
relayBA?: Relay;
routesAB?: NameLike[];
routesBA?: NameLike[];
routesAB?: readonly NameLike[];
routesBA?: readonly NameLike[];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/nac/src/access-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,6 @@ export namespace AccessManager {
* Caller is responsible for verifying authenticity of the PublicKey or Certificate.
* If passing a key name or certificate name, the retrieved certificate will be verified by Options.memberVerifier.
*/
grant: (member: NamedEncrypter.PublicKey | Certificate | Name) => Promise<KeyDecryptionKey>;
grant(member: NamedEncrypter.PublicKey | Certificate | Name): Promise<KeyDecryptionKey>;
}
}
4 changes: 2 additions & 2 deletions packages/ndncert/src/client/challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ export interface ClientChallenge {
* Create a message to select and start the challenge.
* @returns parameter key-value pairs to send to server in initial CHALLENGE request.
*/
start: (context: ClientChallengeStartContext) => Promise<ParameterKV>;
start(context: ClientChallengeStartContext): Promise<ParameterKV>;

/**
* Create a message to continue the challenge.
* @returns parameter key-value pairs to send to server in continuing CHALLENGE request.
*/
next: (context: ClientChallengeContext) => Promise<ParameterKV>;
next(context: ClientChallengeContext): Promise<ParameterKV>;
}

/** Contextual information for challenge selection. */
Expand Down
2 changes: 1 addition & 1 deletion packages/ndncert/src/packet/challenge-request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export namespace ChallengeRequest {
* @param requestId request session ID.
* @returns request session information, or undefined if not found.
*/
lookupRequest: (requestId: Uint8Array) => Promisable<RequestInfo | undefined>;
lookupRequest(requestId: Uint8Array): Promisable<RequestInfo | undefined>;
}

/** Fields of CHALLENGE request packet. */
Expand Down
2 changes: 1 addition & 1 deletion packages/ndncert/src/server/challenge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export interface ServerChallenge<State = any> {
readonly retryLimit: number;

/** Process selection or continuation of the challenge. */
process: (request: ChallengeRequest, context: ServerChallengeContext<State>) => Promise<ServerChallengeResponse>;
process(request: ChallengeRequest, context: ServerChallengeContext<State>): Promise<ServerChallengeResponse>;
}

/** Contextual information for challenge processing. */
Expand Down
2 changes: 1 addition & 1 deletion packages/ndncert/src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export namespace ServerOptions {
}

interface RepoDataStore {
insert: (data: Data) => Promise<void>;
insert(data: Data): Promise<void>;
}

/** NDNCERT server. */
Expand Down
2 changes: 1 addition & 1 deletion packages/ndncert/tests/server-client.t.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { CaProfile, type ClientChallenge, type ClientChallengeContext, ClientEma

interface Row {
summary: string;
makeChallengeLists: () => Promise<[ServerChallenge[], ClientChallenge[]]>;
makeChallengeLists(): Promise<[ServerChallenge[], ClientChallenge[]]>;
clientShouldFail?: boolean;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/packet/src/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ definePublicFields<Data, Fields, PublicFields>(Data, {

const ctorAssign = Symbol("Data.ctorAssign");
interface CtorTag {
[ctorAssign]: (f: Fields) => void;
[ctorAssign](f: Fields): void;
}

export namespace Data {
Expand Down
2 changes: 1 addition & 1 deletion packages/packet/src/interest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ definePublicFields<Interest, Fields, PublicFields>(Interest, {

const ctorAssign = Symbol("Interest.ctorAssign");
interface CtorTag {
[ctorAssign]: (f: Fields) => void;
[ctorAssign](f: Fields): void;
}

export namespace Interest {
Expand Down
10 changes: 5 additions & 5 deletions packages/packet/src/name/convention.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ import type { Component } from "./component";
*/
export interface NamingConvention<A, R = A> {
/** Determine if a component follows this naming convention. */
match: (comp: Component) => boolean;
match(comp: Component): boolean;

/** Create a component from input value following this naming convention. */
create: (v: A) => Component;
create(v: A): Component;

/** Parse value of a matched component. */
parse: (comp: Component) => R;
parse(comp: Component): R;
}

export namespace NamingConvention {
/** A naming convention that supports alternate/pretty URI. */
export interface WithAltUri {
/** Convert to alternate URI. */
toAltUri: (comp: Component) => string;
toAltUri(comp: Component): string;

/**
* Parse from alternate URI.
* @returns component, or undefined if it cannot be parsed.
*/
fromAltUri: (input: string) => Component | undefined;
fromAltUri(input: string): Component | undefined;
}

export function isConvention(obj: any): obj is NamingConvention<any> {
Expand Down
4 changes: 2 additions & 2 deletions packages/packet/src/security/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export namespace LLDecrypt {
*/
export interface Encrypter<T = Data> {
/** Encrypt a packet. The packet is modified in-place. */
encrypt: (pkt: T) => Promise<void>;
encrypt(pkt: T): Promise<void>;
}

/**
Expand All @@ -64,7 +64,7 @@ export interface Encrypter<T = Data> {
*/
export interface Decrypter<T = Data> {
/** Decrypt a packet. The packet is modified in-place. */
decrypt: (pkt: T) => Promise<void>;
decrypt(pkt: T): Promise<void>;
}

/** Encrypter and decrypter that do nothing. */
Expand Down
Loading

0 comments on commit 9e29786

Please sign in to comment.