Skip to content

Commit

Permalink
Avoid {} in types
Browse files Browse the repository at this point in the history
  • Loading branch information
ai committed Oct 18, 2024
1 parent b3b8836 commit 211f51c
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 23 deletions.
4 changes: 2 additions & 2 deletions add-http-pages/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let lastPort = 9111

function createServer(
options: Partial<BaseServerOptions> = {}
): BaseServer<{}, TestLog<ServerMeta>> {
): BaseServer<object, TestLog<ServerMeta>> {
let opts = {
...DEFAULT_OPTIONS,
...options
Expand All @@ -32,7 +32,7 @@ function createServer(
opts.port = lastPort
}

let created = new BaseServer<{}, TestLog<ServerMeta>>(opts)
let created = new BaseServer<object, TestLog<ServerMeta>>(opts)
created.auth(() => true)

destroyable = created
Expand Down
22 changes: 11 additions & 11 deletions base-server/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ interface ChannelOptions {
queue?: string
}

interface ConnectLoader<Headers extends object = {}> {
interface ConnectLoader<Headers extends object = unknown> {
(ctx: ConnectContext<Headers>, lastSynced: number):
| [Action, ServerMeta][]
| Promise<
Expand Down Expand Up @@ -358,7 +358,7 @@ interface ActionFinally<
*/
interface ChannelFilter<Headers extends object> {
(
ctx: Context<{}, Headers>,
ctx: Context<unknown, Headers>,
action: Readonly<Action>,
meta: Readonly<ServerMeta>
): boolean | Promise<boolean>
Expand Down Expand Up @@ -637,7 +637,7 @@ export function wasNot403(cb: () => Promise<void>): Promise<boolean>
* Base server class to extend.
*/
export class BaseServer<
Headers extends object = {},
Headers extends object = unknown,
ServerLog extends Log = Log<ServerMeta>
> {
/**
Expand Down Expand Up @@ -734,7 +734,7 @@ export class BaseServer<
subscribers: {
[channel: string]: {
[nodeId: string]: {
filters: Record<string, ChannelFilter<{}> | true>
filters: Record<string, ChannelFilter<unknown> | true>
unsubscribe?: (action: LoguxUnsubscribeAction, meta: ServerMeta) => void
}
}
Expand Down Expand Up @@ -806,8 +806,8 @@ export class BaseServer<
* @param options Additional options
*/
channel<
ChannelParams extends object = {},
Data extends object = {},
ChannelParams extends object = unknown,
Data extends object = unknown,
SubscribeAction extends LoguxSubscribeAction = LoguxSubscribeAction
>(
pattern: string,
Expand All @@ -822,7 +822,7 @@ export class BaseServer<
*/
channel<
ChannelParams extends string[] = string[],
Data extends object = {},
Data extends object = unknown,
SubscribeAction extends LoguxSubscribeAction = LoguxSubscribeAction
>(
pattern: RegExp,
Expand Down Expand Up @@ -1054,7 +1054,7 @@ export class BaseServer<
*
* @param callbacks Callback during subscription process.
*/
otherChannel<Data extends object = {}>(
otherChannel<Data extends object = unknown>(
callbacks: ChannelCallbacks<LoguxSubscribeAction, Data, [string], Headers>
): void

Expand Down Expand Up @@ -1084,7 +1084,7 @@ export class BaseServer<
*
* @param callbacks Callbacks for actions with this type.
*/
otherType<Data extends object = {}>(
otherType<Data extends object = unknown>(
callbacks: ActionCallbacks<Action, Data, Headers>
): void

Expand Down Expand Up @@ -1151,7 +1151,7 @@ export class BaseServer<
* @param callbacks Callbacks for action created by creator.
* @param options Additional options
*/
type<Creator extends AbstractActionCreator, Data extends object = {}>(
type<Creator extends AbstractActionCreator, Data extends object = unknown>(
actionCreator: Creator,
callbacks: ActionCallbacks<ReturnType<Creator>, Data, Headers>,
options?: TypeOptions
Expand Down Expand Up @@ -1180,7 +1180,7 @@ export class BaseServer<
* @param callbacks Callbacks for actions with this type.
* @param options Additional options
*/
type<TypeAction extends Action = AnyAction, Data extends object = {}>(
type<TypeAction extends Action = AnyAction, Data extends object = unknown>(
name: RegExp | TypeAction['type'],
callbacks: ActionCallbacks<TypeAction, Data, Headers>,
options?: TypeOptions
Expand Down
6 changes: 3 additions & 3 deletions base-server/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ let lastPort = 9111

function createServer(
options: Partial<BaseServerOptions> = {}
): BaseServer<{}, TestLog<ServerMeta>> {
): BaseServer<object, TestLog<ServerMeta>> {
let opts = {
...DEFAULT_OPTIONS,
...options
Expand All @@ -49,7 +49,7 @@ function createServer(
opts.port = lastPort
}

let created = new BaseServer<{}, TestLog<ServerMeta>>(opts)
let created = new BaseServer<object, TestLog<ServerMeta>>(opts)
created.auth(() => true)

destroyable = created
Expand All @@ -61,7 +61,7 @@ let destroyable: BaseServer | undefined
let httpServer: http.Server | undefined

function createReporter(opts: Partial<BaseServerOptions> = {}): {
app: BaseServer<{}, TestLog<ServerMeta>>
app: BaseServer<object, TestLog<ServerMeta>>
names: string[]
reports: [string, any][]
} {
Expand Down
6 changes: 3 additions & 3 deletions context/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { ServerMeta } from '../base-server/index.js'
import type { ServerClient } from '../server-client/index.js'
import type { Server } from '../server/index.js'

export class ConnectContext<Headers extends object = {}> {
export class ConnectContext<Headers extends object = unknown> {
/**
* Unique persistence client ID.
*
Expand Down Expand Up @@ -103,8 +103,8 @@ export class ConnectContext<Headers extends object = {}> {
* ```
*/
export class Context<
Data extends object = {},
Headers extends object = {}
Data extends object = unknown,
Headers extends object = unknown
> extends ConnectContext<Headers> {
/**
* Open structure to save some data between different steps of processing.
Expand Down
2 changes: 1 addition & 1 deletion filtered-node/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { afterEach, expect, it } from 'vitest'
import { FilteredNode } from '../filtered-node/index.js'

type Test = {
client: ClientNode<{}, TestLog>
client: ClientNode<object, TestLog>
server: FilteredNode
}

Expand Down
4 changes: 3 additions & 1 deletion server/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ export interface ServerOptions extends BaseServerOptions {
* server.listen()
* ```
*/
export class Server<Headers extends object = {}> extends BaseServer<Headers> {
export class Server<
Headers extends object = unknown
> extends BaseServer<Headers> {
/**
* Server options.
*
Expand Down
2 changes: 1 addition & 1 deletion test-client/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ it('detects action ID duplicate', async () => {

it('tracks subscriptions', async () => {
server = new TestServer()
server.channel<{}, {}, LoguxSubscribeAction>('foo', {
server.channel<object, object, LoguxSubscribeAction>('foo', {
access: () => true,
load(ctx, action) {
ctx.sendBack({ a: action.filter?.a, since: action.since, type: 'FOO' })
Expand Down
2 changes: 1 addition & 1 deletion test-server/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export interface TestServerOptions
* ```
*/
export class TestServer<
Headers extends object = {}
Headers extends object = unknown
> extends BaseServer<Headers> {
/**
* fetch() compatible API to test HTTP endpoints.
Expand Down

0 comments on commit 211f51c

Please sign in to comment.