chore: update version to 2025.0.8 and refactor Channels class to improve channel management methods
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@techniker-me/pcast-api",
|
"name": "@techniker-me/pcast-api",
|
||||||
"version": "2025.0.7",
|
"version": "2025.0.8",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"ci-build": "bun run build:node && bun run build:browser && bun run build:types",
|
"ci-build": "bun run build:node && bun run build:browser && bun run build:types",
|
||||||
|
|||||||
@@ -56,24 +56,6 @@ export class Channels {
|
|||||||
this.initialize();
|
this.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
private async initialize() {
|
|
||||||
try {
|
|
||||||
const channelsList = await this.list();
|
|
||||||
if (!channelsList) {
|
|
||||||
console.warn('[Channels] Failed to initialize cache - no channels returned');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const channel of channelsList) {
|
|
||||||
this._channelsByAlias.set(channel.alias, channel);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._initialized = true;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('[Channels] Failed to initialize cache:', error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public async createChannel(name: string, description: string, channelOptions: string[] = []): Promise<Channel> {
|
public async createChannel(name: string, description: string, channelOptions: string[] = []): Promise<Channel> {
|
||||||
// Input validation
|
// Input validation
|
||||||
if (!name || name.trim().length === 0) {
|
if (!name || name.trim().length === 0) {
|
||||||
@@ -159,7 +141,7 @@ export class Channels {
|
|||||||
return parseInt(response, 10);
|
return parseInt(response, 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getMembers(channelId: string): Promise<Member[]> {
|
public async getChannelMembers(channelId: string): Promise<Member[]> {
|
||||||
if (!channelId || channelId.trim().length === 0) {
|
if (!channelId || channelId.trim().length === 0) {
|
||||||
throw new ChannelError('Channel ID cannot be empty', 'INVALID_CHANNEL_ID');
|
throw new ChannelError('Channel ID cannot be empty', 'INVALID_CHANNEL_ID');
|
||||||
}
|
}
|
||||||
@@ -173,6 +155,16 @@ export class Channels {
|
|||||||
return response.members;
|
return response.members;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public async getChannelMembersByAlias(alias: string): Promise<Member[]> {
|
||||||
|
const channel = await this.get({alias});
|
||||||
|
|
||||||
|
if (!channel) {
|
||||||
|
throw new ChannelError(`Channel not found: ${alias}`, 'CHANNEL_NOT_FOUND');
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.getChannelMembers(channel.channelId);
|
||||||
|
}
|
||||||
|
|
||||||
public async deleteChannel(channelId: string): Promise<Channel> {
|
public async deleteChannel(channelId: string): Promise<Channel> {
|
||||||
return this.delete(channelId);
|
return this.delete(channelId);
|
||||||
}
|
}
|
||||||
@@ -210,4 +202,22 @@ export class Channels {
|
|||||||
public getCacheSize(): number {
|
public getCacheSize(): number {
|
||||||
return this._channelsByAlias.size;
|
return this._channelsByAlias.size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async initialize() {
|
||||||
|
try {
|
||||||
|
const channelsList = await this.list();
|
||||||
|
if (!channelsList) {
|
||||||
|
console.warn('[Channels] Failed to initialize cache - no channels returned');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const channel of channelsList) {
|
||||||
|
this._channelsByAlias.set(channel.alias, channel);
|
||||||
|
}
|
||||||
|
|
||||||
|
this._initialized = true;
|
||||||
|
} catch (error) {
|
||||||
|
console.error('[Channels] Failed to initialize cache:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user