Skip to content

Commit

Permalink
[feat] added support for stream info deleted sequences - FIX #143 (#150)
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Apr 23, 2021
1 parent 36b969c commit 042d7c1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:

strategy:
matrix:
deno-version: [1.8.3, 1.9.0]
deno-version: [1.8.3, 1.9.2]

steps:
- name: Git Checkout Deno Module
Expand All @@ -30,7 +30,7 @@ jobs:
deno-version: ${{ matrix.deno-version }}

- name: Set NATS Server Version
run: echo "NATS_VERSION=v2.2.1" >> $GITHUB_ENV
run: echo "NATS_VERSION=v2.2.2" >> $GITHUB_ENV

- name: Get nats-server
run: |
Expand Down
8 changes: 6 additions & 2 deletions nats-base-client/jsstream_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
StreamAPI,
StreamConfig,
StreamInfo,
StreamInfoRequestOptions,
StreamListResponse,
StreamMsgResponse,
SuccessResponse,
Expand Down Expand Up @@ -64,9 +65,12 @@ export class StreamAPIImpl extends BaseApiClient implements StreamAPI {
return r as StreamInfo;
}

async info(name: string): Promise<StreamInfo> {
async info(
name: string,
data?: StreamInfoRequestOptions,
): Promise<StreamInfo> {
validateStreamName(name);
const r = await this._request(`${this.prefix}.STREAM.INFO.${name}`);
const r = await this._request(`${this.prefix}.STREAM.INFO.${name}`, data);
return r as StreamInfo;
}

Expand Down
7 changes: 6 additions & 1 deletion nats-base-client/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -355,8 +355,12 @@ export interface ConsumerAPI {
list(stream: string): Lister<ConsumerInfo>;
}

export type StreamInfoRequestOptions = {
"deleted_details": boolean;
};

export interface StreamAPI {
info(stream: string): Promise<StreamInfo>;
info(stream: string, opts?: StreamInfoRequestOptions): Promise<StreamInfo>;
add(cfg: Partial<StreamConfig>): Promise<StreamInfo>;
update(cfg: StreamConfig): Promise<StreamInfo>;
purge(stream: string): Promise<PurgeResponse>;
Expand Down Expand Up @@ -533,6 +537,7 @@ export interface StreamState {
"first_ts": number;
"last_seq": number;
"last_ts": string;
"num_deleted": number;
deleted: number[];
lost: LostStreamData;
"consumer_count": number;
Expand Down
19 changes: 19 additions & 0 deletions tests/jsm_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,25 @@ Deno.test("jsm - stream delete message", async () => {
await cleanup(ns, nc);
});

Deno.test("jsm - stream delete info", async () => {
const { ns, nc } = await setup(jetstreamServerConf());

const { stream, subj } = await initStream(nc);
const jsm = await nc.jetstreamManager();

const js = nc.jetstream();
await js.publish(subj);
await js.publish(subj);
await js.publish(subj);
await jsm.streams.deleteMessage(stream, 2);

const si = await jsm.streams.info(stream, { deleted_details: true });
assertEquals(si.state.num_deleted, 1);
assertEquals(si.state.deleted, [2]);

await cleanup(ns, nc);
});

Deno.test("jsm - consumer info on empty stream name fails", async () => {
const { ns, nc } = await setup(jetstreamServerConf({}, true));
const jsm = await nc.jetstreamManager();
Expand Down

0 comments on commit 042d7c1

Please sign in to comment.