Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
"quoteProperties": "asNeeded",
"quoteStyle": "single",
"semicolons": "always",
"trailingComma": "all"
},
"globals": ["setup", "suite", "suiteSetup", "teardown", "test"]
"trailingCommas": "all"
}
},
"json": {
"formatter": {
Expand All @@ -38,9 +37,15 @@
"enabled": true,
"rules": {
"all": true,
"correctness": {
"noNodejsModules": "off"
},
"nursery": {
"useImportRestrictions": "off"
}
},
"style": {
"useFilenamingConvention": "off"
}
}
},
"organizeImports": {
Expand Down
42 changes: 21 additions & 21 deletions lib/Client.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import { ClientConfiguration } from './ClientConfiguration';
import { ClientOptions } from './ClientOptions';
import { EventCandidate } from './event/EventCandidate';
import { EventContext } from './event/EventContext';
import { getDefaultClientConfiguration } from './getDefaultClientConfiguration';
import { StoreItem } from './handlers/StoreItem';
import { ObserveEventsOptions } from './handlers/observeEvents/ObserveEventsOptions';
import { observeEvents } from './handlers/observeEvents/observeEvents';
import { ping } from './handlers/ping/ping';
import { EventType } from './handlers/readEventTypes/EventType';
import { readEventTypes } from './handlers/readEventTypes/readEventTypes';
import { ReadEventsOptions } from './handlers/readEvents/ReadEventsOptions';
import { readEvents } from './handlers/readEvents/readEvents';
import { ReadSubjectsOptions } from './handlers/readSubjects/ReadSubjectsOptions';
import { readSubjects } from './handlers/readSubjects/readSubjects';
import { registerEventSchema } from './handlers/registerEventSchema/registerEventSchema';
import { Precondition } from './handlers/writeEvents/Precondition';
import { writeEvents } from './handlers/writeEvents/writeEvents';
import { HttpClient } from './http/HttpClient';
import type { ClientConfiguration } from './ClientConfiguration.js';
import type { ClientOptions } from './ClientOptions.js';
import type { EventCandidate } from './event/EventCandidate.js';
import type { EventContext } from './event/EventContext.js';
import { getDefaultClientConfiguration } from './getDefaultClientConfiguration.js';
import type { StoreItem } from './handlers/StoreItem.js';
import type { ObserveEventsOptions } from './handlers/observeEvents/ObserveEventsOptions.js';
import { observeEvents } from './handlers/observeEvents/observeEvents.js';
import { ping } from './handlers/ping/ping.js';
import type { EventType } from './handlers/readEventTypes/EventType.js';
import { readEventTypes } from './handlers/readEventTypes/readEventTypes.js';
import type { ReadEventsOptions } from './handlers/readEvents/ReadEventsOptions.js';
import { readEvents } from './handlers/readEvents/readEvents.js';
import type { ReadSubjectsOptions } from './handlers/readSubjects/ReadSubjectsOptions.js';
import { readSubjects } from './handlers/readSubjects/readSubjects.js';
import { registerEventSchema } from './handlers/registerEventSchema/registerEventSchema.js';
import type { Precondition } from './handlers/writeEvents/Precondition.js';
import { writeEvents } from './handlers/writeEvents/writeEvents.js';
import { HttpClient } from './http/HttpClient.js';

class Client {
public readonly configuration: ClientConfiguration;
Expand Down Expand Up @@ -62,14 +62,14 @@ class Client {
}

public async registerEventSchema(eventType: string, schema: string | object): Promise<void> {
return registerEventSchema(this, eventType, schema);
return await registerEventSchema(this, eventType, schema);
}

public async writeEvents(
eventCandidates: EventCandidate[],
preconditions: Precondition[] = [],
): Promise<EventContext[]> {
return writeEvents(this, eventCandidates, preconditions);
return await writeEvents(this, eventCandidates, preconditions);
}
}

Expand Down
3 changes: 1 addition & 2 deletions lib/ClientConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ interface ClientConfiguration {
timeoutMilliseconds: number;
accessToken: string;
protocolVersion: string;
maxTries: number;
}

export { ClientConfiguration };
export type { ClientConfiguration };
3 changes: 1 addition & 2 deletions lib/ClientOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ interface ClientOptions {
timeoutMilliseconds?: number;
accessToken: string;
protocolVersion?: string;
maxTries?: number;
}

export { ClientOptions };
export type { ClientOptions };
6 changes: 3 additions & 3 deletions lib/event/Event.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { UnknownObject } from '../util/UnknownObject';
import { isObject } from '../util/isObject';
import { EventContext } from './EventContext';
import type { UnknownObject } from '../util/UnknownObject.js';
import { isObject } from '../util/isObject.js';
import { EventContext } from './EventContext.js';

class Event extends EventContext {
public readonly data: Record<string, unknown>;
Expand Down
8 changes: 4 additions & 4 deletions lib/event/EventCandidate.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UnknownObject } from '../util/UnknownObject';
import { ValidationError } from '../util/error/ValidationError';
import { validateSubject } from './validateSubject';
import { validateType } from './validateType';
import type { UnknownObject } from '../util/UnknownObject.js';
import { ValidationError } from '../util/error/ValidationError.js';
import { validateSubject } from './validateSubject.js';
import { validateType } from './validateType.js';

class EventCandidate {
public readonly data: Record<string, unknown>;
Expand Down
8 changes: 4 additions & 4 deletions lib/event/EventContext.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { UnknownObject } from '../util/UnknownObject';
import { ValidationError } from '../util/error/ValidationError';
import { validateSubject } from './validateSubject';
import { validateType } from './validateType';
import type { UnknownObject } from '../util/UnknownObject.js';
import { ValidationError } from '../util/error/ValidationError.js';
import { validateSubject } from './validateSubject.js';
import { validateType } from './validateType.js';

class EventContext {
public readonly source: string;
Expand Down
4 changes: 2 additions & 2 deletions lib/event/Source.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { UnknownObject } from '../util/UnknownObject';
import { EventCandidate } from './EventCandidate';
import type { UnknownObject } from '../util/UnknownObject.js';
import { EventCandidate } from './EventCandidate.js';

class Source {
public readonly source: string;
Expand Down
2 changes: 1 addition & 1 deletion lib/event/validateSubject.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ValidationError } from '../util/error/ValidationError';
import { ValidationError } from '../util/error/ValidationError.js';

const wordPattern = '[0-9A-Za-z_-]+';
const subjectPattern = new RegExp(`^/(${wordPattern}/)*(${wordPattern}/?)?$`, 'u');
Expand Down
2 changes: 1 addition & 1 deletion lib/event/validateType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ValidationError } from '../util/error/ValidationError';
import { ValidationError } from '../util/error/ValidationError.js';

const typePattern = /^[0-9A-Za-z_-]{2,}\.(?:[0-9A-Za-z_-]+\.)+[0-9A-Za-z_-]+$/u;

Expand Down
3 changes: 1 addition & 2 deletions lib/getDefaultClientConfiguration.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { ClientConfiguration } from './ClientConfiguration';
import type { ClientConfiguration } from './ClientConfiguration.js';

const getDefaultClientConfiguration = (baseUrl: string): ClientConfiguration => {
return {
baseUrl,
timeoutMilliseconds: 10_000,
accessToken: '',
protocolVersion: '1.0.0',
maxTries: 10,
};
};

Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/Heartbeat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ interface Heartbeat {
type: 'heartbeat';
}

export { Heartbeat };
export type { Heartbeat };
4 changes: 2 additions & 2 deletions lib/handlers/Item.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { UnknownObject } from '../util/UnknownObject';
import type { UnknownObject } from '../util/UnknownObject.js';

interface Item {
type: 'item';
Expand All @@ -8,4 +8,4 @@ interface Item {
};
}

export { Item };
export type { Item };
4 changes: 2 additions & 2 deletions lib/handlers/StoreItem.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Event } from '../event/Event';
import type { Event } from '../event/Event.js';

interface StoreItem {
event: Event;
hash: string;
}

export { StoreItem };
export type { StoreItem };
2 changes: 1 addition & 1 deletion lib/handlers/StreamError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ interface StreamError {
};
}

export { StreamError };
export type { StreamError };
4 changes: 2 additions & 2 deletions lib/handlers/isHeartbeat.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isObject } from '../util/isObject';
import { Heartbeat } from './Heartbeat';
import { isObject } from '../util/isObject.js';
import type { Heartbeat } from './Heartbeat.js';

const isHeartbeat = (message: unknown): message is Heartbeat => {
return isObject(message) && message.type === 'heartbeat';
Expand Down
4 changes: 2 additions & 2 deletions lib/handlers/isItem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isObject } from '../util/isObject';
import { Item } from './Item';
import { isObject } from '../util/isObject.js';
import type { Item } from './Item.js';

const isItem = (message: unknown): message is Item => {
if (!isObject(message) || message.type !== 'item') {
Expand Down
4 changes: 2 additions & 2 deletions lib/handlers/isStreamError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { isObject } from '../util/isObject';
import { StreamError } from './StreamError';
import { isObject } from '../util/isObject.js';
import type { StreamError } from './StreamError.js';

const isStreamError = (message: unknown): message is StreamError => {
if (!isObject(message) || message.type !== 'error') {
Expand Down
13 changes: 7 additions & 6 deletions lib/handlers/observeEvents/ObserveEventsOptions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { validateSubject } from '../../event/validateSubject';
import { validateType } from '../../event/validateType';
import { ValidationError } from '../../util/error/ValidationError';
import { wrapError } from '../../util/error/wrapError';
import { IsNonNegativeInteger } from '../../util/isNonNegativeInteger';
import { validateSubject } from '../../event/validateSubject.js';
import { validateType } from '../../event/validateType.js';
import { ValidationError } from '../../util/error/ValidationError.js';
import { wrapError } from '../../util/error/wrapError.js';
import { IsNonNegativeInteger } from '../../util/isNonNegativeInteger.js';

interface ObserveEventsOptions {
recursive: boolean;
Expand Down Expand Up @@ -45,4 +45,5 @@ const validateObserveEventsOptions = (options: ObserveEventsOptions): void => {
}
};

export { ObserveEventsOptions, ObserveFromLatestEvent, validateObserveEventsOptions };
export type { ObserveEventsOptions, ObserveFromLatestEvent };
export { validateObserveEventsOptions };
33 changes: 17 additions & 16 deletions lib/handlers/observeEvents/observeEvents.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { StatusCodes, getReasonPhrase } from 'http-status-codes';
import { Client } from '../../Client';
import { Event } from '../../event/Event';
import { validateSubject } from '../../event/validateSubject';
import { CustomError } from '../../util/error/CustomError';
import { InternalError } from '../../util/error/InternalError';
import { InvalidParameterError } from '../../util/error/InvalidParameterError';
import { ServerError } from '../../util/error/ServerError';
import { ValidationError } from '../../util/error/ValidationError';
import { wrapError } from '../../util/error/wrapError';
import { readNdJsonStream } from '../../util/ndjson/readNdJsonStream';
import { StoreItem } from '../StoreItem';
import { isHeartbeat } from '../isHeartbeat';
import { isItem } from '../isItem';
import { isStreamError } from '../isStreamError';
import { ObserveEventsOptions, validateObserveEventsOptions } from './ObserveEventsOptions';
import type { Client } from '../../Client.js';
import { Event } from '../../event/Event.js';
import { validateSubject } from '../../event/validateSubject.js';
import { CustomError } from '../../util/error/CustomError.js';
import { InternalError } from '../../util/error/InternalError.js';
import { InvalidParameterError } from '../../util/error/InvalidParameterError.js';
import { ServerError } from '../../util/error/ServerError.js';
import { ValidationError } from '../../util/error/ValidationError.js';
import { wrapError } from '../../util/error/wrapError.js';
import { readNdJsonStream } from '../../util/ndjson/readNdJsonStream.js';
import type { StoreItem } from '../StoreItem.js';
import { isHeartbeat } from '../isHeartbeat.js';
import { isItem } from '../isItem.js';
import { isStreamError } from '../isStreamError.js';
import { validateObserveEventsOptions } from './ObserveEventsOptions.js';
import type { ObserveEventsOptions } from './ObserveEventsOptions.js';

const observeEvents = async function* (
client: Client,
Expand Down Expand Up @@ -63,7 +64,7 @@ const observeEvents = async function* (
responseType: 'stream',
abortController,
}),
async error => {
error => {
if (error instanceof CustomError) {
throw error;
}
Expand Down
12 changes: 6 additions & 6 deletions lib/handlers/ping/ping.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Client } from '../../Client';
import { CustomError } from '../../util/error/CustomError';
import { InternalError } from '../../util/error/InternalError';
import { ServerError } from '../../util/error/ServerError';
import { wrapError } from '../../util/error/wrapError';
import type { Client } from '../../Client.js';
import { CustomError } from '../../util/error/CustomError.js';
import { InternalError } from '../../util/error/InternalError.js';
import { ServerError } from '../../util/error/ServerError.js';
import { wrapError } from '../../util/error/wrapError.js';

const ping = async (client: Client): Promise<void> => {
const response = await wrapError(
Expand All @@ -12,7 +12,7 @@ const ping = async (client: Client): Promise<void> => {
responseType: 'text',
withAuthorization: false,
}),
async error => {
error => {
if (error instanceof CustomError) {
throw error;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/handlers/readEventTypes/EventType.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isObject } from '../../util/isObject';
import { isObject } from '../../util/isObject.js';

interface EventType {
eventType: string;
Expand Down
21 changes: 11 additions & 10 deletions lib/handlers/readEventTypes/readEventTypes.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { StatusCodes } from 'http-status-codes';
import { Client } from '../../Client';
import { CustomError } from '../../util/error/CustomError';
import { InternalError } from '../../util/error/InternalError';
import { ServerError } from '../../util/error/ServerError';
import { wrapError } from '../../util/error/wrapError';
import { readNdJsonStream } from '../../util/ndjson/readNdJsonStream';
import { isHeartbeat } from '../isHeartbeat';
import { isStreamError } from '../isStreamError';
import { EventType, isEventType } from './EventType';
import type { Client } from '../../Client.js';
import { CustomError } from '../../util/error/CustomError.js';
import { InternalError } from '../../util/error/InternalError.js';
import { ServerError } from '../../util/error/ServerError.js';
import { wrapError } from '../../util/error/wrapError.js';
import { readNdJsonStream } from '../../util/ndjson/readNdJsonStream.js';
import { isHeartbeat } from '../isHeartbeat.js';
import { isStreamError } from '../isStreamError.js';
import type { EventType } from './EventType.js';
import { isEventType } from './EventType.js';

const readEventTypes = async function* (
client: Client,
Expand All @@ -21,7 +22,7 @@ const readEventTypes = async function* (
responseType: 'stream',
abortController,
}),
async error => {
error => {
if (error instanceof CustomError) {
throw error;
}
Expand Down
13 changes: 7 additions & 6 deletions lib/handlers/readEvents/ReadEventsOptions.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { validateSubject } from '../../event/validateSubject';
import { validateType } from '../../event/validateType';
import { ValidationError } from '../../util/error/ValidationError';
import { wrapError } from '../../util/error/wrapError';
import { IsNonNegativeInteger } from '../../util/isNonNegativeInteger';
import { validateSubject } from '../../event/validateSubject.js';
import { validateType } from '../../event/validateType.js';
import { ValidationError } from '../../util/error/ValidationError.js';
import { wrapError } from '../../util/error/wrapError.js';
import { IsNonNegativeInteger } from '../../util/isNonNegativeInteger.js';

interface ReadEventsOptions {
recursive: boolean;
Expand Down Expand Up @@ -50,4 +50,5 @@ const validateReadEventsOptions = (options: ReadEventsOptions): void => {
}
};

export { ReadEventsOptions, ReadFromLatestEvent, validateReadEventsOptions };
export type { ReadEventsOptions, ReadFromLatestEvent };
export { validateReadEventsOptions };
Loading
Loading