Skip to content

Commit

Permalink
[FEAT] objectstore (wip)
Browse files Browse the repository at this point in the history
  • Loading branch information
aricart committed Aug 3, 2022
1 parent 350dfe9 commit 42fd0ea
Show file tree
Hide file tree
Showing 6 changed files with 979 additions and 1 deletion.
11 changes: 11 additions & 0 deletions nats-base-client/databuffer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ export class DataBuffer {
}
}

shift(): Uint8Array {
if (this.buffers.length) {
const a = this.buffers.shift();
if (a) {
this.byteLength -= a.length;
return a;
}
}
return new Uint8Array(0);
}

drain(n?: number): Uint8Array {
if (this.buffers.length) {
this.pack();
Expand Down
16 changes: 16 additions & 0 deletions nats-base-client/headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,20 @@ export class MsgHdrsImpl implements MsgHdrs {
get status(): string {
return `${this.code} ${this.description}`.trim();
}

toRecord(): Record<string, string[]> {
const data = {} as Record<string, string[]>;
this.keys().forEach((v) => {
data[v] = this.values(v);
});
return data;
}

static fromRecord(r: Record<string, string[]>): MsgHdrs {
const h = new MsgHdrsImpl();
for (const k in r) {
h.headers.set(k, r[k]);
}
return h;
}
}
16 changes: 15 additions & 1 deletion nats-base-client/jsclient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,14 @@
* limitations under the License.
*/

import type { ConsumerOptsBuilder, KV, KvOptions, Views } from "./types.ts";
import type {
ConsumerOptsBuilder,
KV,
KvOptions,
ObjectStore,
ObjectStoreOptions,
Views,
} from "./types.ts";
import {
AckPolicy,
ConsumerAPI,
Expand Down Expand Up @@ -72,6 +79,7 @@ import { consumerOpts, isConsumerOptsBuilder } from "./jsconsumeropts.ts";
import { Bucket } from "./kv.ts";
import { NatsConnectionImpl } from "./nats.ts";
import { Feature } from "./semver.ts";
import { ObjectStoreImpl } from "./objectstore.ts";

export interface JetStreamSubscriptionInfoable {
info: JetStreamSubscriptionInfo | null;
Expand All @@ -97,6 +105,12 @@ class ViewsImpl implements Views {
}
return Bucket.create(this.js, name, opts);
}
os(
name: string,
opts: Partial<ObjectStoreOptions> = {},
): Promise<ObjectStore> {
return ObjectStoreImpl.create(this.js, name, opts);
}
}

export class JetStreamClientImpl extends BaseApiClient
Expand Down
Loading

0 comments on commit 42fd0ea

Please sign in to comment.